Sign in to follow this  
xx6heartless6xx

Passing Objects [C++]

Recommended Posts

I want to pass my array of Tile objects in the set_Tiles function but i always seem to be getting an error. Here is my main function and the header file where the set_Tiles function is right under.

[code]
int main() {
//Tile object
Tile tiles[529];

//Set the current gamestate object
GameState* currentState = new Level_One( event, STATE_EXIT, camera, screen, nextState, LEVEL_WIDTH );

currentState->set_Tiles( tiles ); // error
}
[/code]

[code]
#ifndef LEVELONE_H
#define LEVELONE_H

#include "GameState.h"

class Level_One : public GameState {
// Irrelevant things
public:
Level_One( SDL_Event, int, SDL_Rect, SDL_Surface*, int, int );
~Level_One();
void set_Tiles( Tile[] );
};

#endif
[/code]

The error says this:
[code]
error C2061: syntax error : identifier 'Tile'
[/code]

Can someone please tell me how to pass this array of objects correctly and how to pass objects in functions correctly?

Share this post


Link to post
Share on other sites
Dragonion    131
[quote name='xx6heartless6xx' timestamp='1310435201' post='4834087']Can someone please tell me how to pass this array of objects correctly and how to pass objects in functions correctly?[/quote]
The argument to set_Tiles doesn't have a name. Try this:

[font="Courier New"]void set_Tiles( Tile [color="#FF0000"][b]tiles[/b][/color][] ); [/font]

Share this post


Link to post
Share on other sites
[quote name='Dragonion' timestamp='1310437858' post='4834104']
[quote name='xx6heartless6xx' timestamp='1310435201' post='4834087']Can someone please tell me how to pass this array of objects correctly and how to pass objects in functions correctly?[/quote]
The argument to set_Tiles doesn't have a name. Try this:

[font="Courier New"]void set_Tiles( Tile [color="#FF0000"][b]tiles[/b][/color][] ); [/font]
[/quote]

I tried that but it still doesnt work. And correct me if I'm wrong here but I believe you just need to put the object type in the function prototype and you dont need to put the name of the object.

Share this post


Link to post
Share on other sites
Dragonion    131
[quote name='xx6heartless6xx' timestamp='1310438347' post='4834106']I tried that but it still doesnt work. And correct me if I'm wrong here but I believe you just need to put the object type in the function prototype and you dont need to put the name of the object.[/quote]

You are right :) Do you include "GameState.h" in the file with your main function?

Share this post


Link to post
Share on other sites
[quote name='Dragonion' timestamp='1310440778' post='4834111']
[quote name='xx6heartless6xx' timestamp='1310438347' post='4834106']I tried that but it still doesnt work. And correct me if I'm wrong here but I believe you just need to put the object type in the function prototype and you dont need to put the name of the object.[/quote]

You are right :) Do you include "GameState.h" in the file with your main function?
[/quote]

Yes it is included.

Share this post


Link to post
Share on other sites
Dragonion    131
[quote name='xx6heartless6xx' timestamp='1310441056' post='4834115']Yes it is included.[/quote]
Ok. Try to read the description of the error message (it basically tells you that "Tile" is not recognized the place in your code where the error is generated):
http://msdn.microsoft.com/en-us/library/yha416c7%28v=vs.80%29.aspx

Share this post


Link to post
Share on other sites
Dragonion    131
[quote name='Dragonion' timestamp='1310440778' post='4834111']You are right :) Do you include "GameState.h" in the file with your main function?[/quote]
Just realized that my intention was to ask you if "Tile.h" was included by the file with your main function. My bad.

Share this post


Link to post
Share on other sites
Dragonion    131
[quote name='xx6heartless6xx' timestamp='1310441904' post='4834120']I've been doing some researching and read about "forward declarations." Is this the solution?[/quote]

No, you can only use forward declarations when your variable is a pointer, like

[font="Courier New"]class MyClass;

void main ( void)
{
MyClass* p; // OK
MyClass a[10]; // error
}

Why can't you just include the file in which you declare Tile?

FYI: I am going to bed now.
[/font]

Share this post


Link to post
Share on other sites
[quote name='Dragonion' timestamp='1310442889' post='4834126']
[quote name='xx6heartless6xx' timestamp='1310441904' post='4834120']I've been doing some researching and read about "forward declarations." Is this the solution?[/quote]

No, you can only use forward declarations when your variable is a pointer, like

[font="Courier New"]class MyClass;

void main ( void)
{
MyClass* p; // OK
MyClass a[10]; // error
}

Why can't you just include the file in which you declare Tile?

FYI: I am going to bed now.
[/font]
[/quote]

Alright thanks man ill keep working on it

Share this post


Link to post
Share on other sites
rip-off    10976
The standard name for a bunch of tiles is a Map, not some kind of "TileManager". Search the forums for the caveats about giving classes vague names like Manager.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this