Tilesheets and SDL

Started by
17 comments, last by rip-off 12 years, 10 months ago
I'm having some problems with lazyfoo's tutorial again :/
Right now I'm at the Tiling tutorial and again the sample code from there works fine (tutorial 29).
But my code is not in just one, but more source files (as shown here).
These are the errors I get:
711053169errors.png
I guess, I forgot to include something, but I have no clue what it could be.

Thanks in advance for any answers :)
Advertisement
In future, please post errors as text. This makes it easier to copy the errors or quote them.

This isn't an "Alternative Games Libraries" issue, its a basic C++ language problem.

The problem is that on classes.h on line 20 the compiler cannot see a declaration of "Tile". This isn't necessarily caused by not including something, it can be caused by the order of includes. Read this, it contains all the information you need to fix this problem.
Looking at the error messages you are using Tile in your code in classes.h without declaring it before. The other error is that you send arguments of the wrong type to Man::move.

I'm having some problems with lazyfoo's tutorial again :/
Right now I'm at the Tiling tutorial and again the sample code from there works fine (tutorial 29).
But my code is not in just one, but more source files (as shown here).
These are the errors I get:
711053169errors.png
I guess, I forgot to include something, but I have no clue what it could be.

Thanks in advance for any answers :)


Since you've modified the code you could you post your code either enclosed source tags or attached as a zip. Otherwise we can only guess what the problem might be.
Patrick
The second error is likely caused by the first, the compiler is using the "default int" fallback while compiling the Man class declaration. Later on the Tile class is declared and then the compiler is confused when a Tile is being passed to what it decided was an int.
The only place I defined "Tile" was in main, but lazyfoo's tutorial does the same.
So far I have "Tile *tiles[TOTAL_TILES];" in main, but I dont know what to do. I've read the article you linked, rip-off, but I still don't know what to do.

If I change the including orders (functions.h before classes.h) I get these errors:
Compiling: game1.cpp
In file included from C:\game1\game1.cpp:9:
C:\game1\functions.h:33: error: 'Tile' was not declared in this scope
C:\game1\functions.h:33: error: 'tiles' was not declared in this scope
C:\game1\functions.h:33: error: expected primary-expression before ']' token
C:\game1\functions.h:35: error: 'Tile' has not been declared
In file included from C:\game1\game1.cpp:11:
C:\game1\classes.h:20: error: 'Tile' has not been declared
C:\game1\game1.cpp: In function 'int SDL_main(int, char**)':
C:\game1\game1.cpp:60: error: 'set_tiles' cannot be used as a function
C:\game1\game1.cpp:86: error: no matching function for call to 'Man::move(int, Tile* [192])'
C:\\game1\classes.h:20: note: candidates are: void Man::move(Uint32, int**)
Process terminated with status 1 (0 minutes, 8 seconds)
7 errors, 0 warnings[/quote]
If I include classes.h before functions.h I get the same errors as above.
Consider splitting your program into more files. Instead of monolithic "classes.h" and "functions.h", separate into additional files such as "tile.h" and "man.h", with the associated source files.
That would still not fix this error.
What I have now is this:
function prototype in class Man: void move(Uint32 deltaTicks, Tile *tiles[]);
To my understanding a function expects input of some sort like int etc. In this case one "Uint32" and one "Tile". My guess would be that "Tile" is defined in one of the SDL libraries, because when everything is in one file it works.
The only other declaration of "Tile" is in my main function, where I use the class to create every Tile-object with "Tile *tiles[TOTAL_TILES];"
Tile is not a SDL type, SDL prefixes its types with "SDL_". Go back to the Lazy Foo tutorials, they probably introduced the Tile type.
Uint32 is defined in SDL.h too (had similar problem before) and no, Tile was not introduced before this tutorial. There is no other definition or declaration in the sample source on lazyfoo either and that works for me.

This topic is closed to new replies.

Advertisement