As an experienced PHP and Java developer, I decided to learn C++. After a few weeks toying around, I decided to port a small game to C++ for the iPod/iPhone/iPad. After writing lots of code last few days, I decided to compile my code to test it, resulting in over 100 compile errors. Although I could fix most of them, I couldn't fix them all, including:
Level.h:26:0: "Block" was not declared in this scope in Level.h: (3 times, same line, same character) I think this one is pretty strange. I include
Block.h in
Level.h...
Block.h compiles without any errors, and
Level.h complains about the class
Block not being declared, even though I just included that file.
Relevant code:
Block.h:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
#ifndef BLOCK_H
#define BLOCK_H
#include "Level.h"
#include "Vertex2D.cpp"
class Block: public Vertex2D<LevelGridUnit>
{
public:
Block(LevelGridUnit x, LevelGridUnit y);
};
#endif
|
Level.h:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#ifndef LEVEL_H
#define LEVEL_H
typedef unsigned short LevelGridUnit;
#include "Tickable.h"
#include "Coordinate2D.cpp"
#include "Vertex2D.cpp"
#include "Block.h"
#include <vector>
#include <string>
class Level: public Tickable
{
protected:
std::vector<Block *> blocks;
std::string message;
Vertex2D<LevelGridUnit> size;
public:
Level(LevelGridUnit width, LevelGridUnit height);
virtual void tick();
Block * getBlockAt(Coordinate2D<LevelGridUnit> & coord);
std::string getMessage();
Vertex2D<LevelGridUnit> getSize();
friend class LevelFactory;
};
#endif
|
LevelLoader.cpp:16:0: Invalid conversion from "void*" to "std::istream*" in LevelLoader.cpp: No comment... just weird. No idea what the origin of this error is.
Relevant code:
LevelLoader.h, line 34
Full source:
http://kutcomputers.nl/wwcode/LevelLoader.h
std::streamoff levelInputStreamDataOffset;
LevelLoader.cpp (stripped for readability, starting at line 12)
Full source:
http://kutcomputers.nl/wwcode/LevelLoader.cpp
1 2 3 4 5 6
|
LevelLoader::LevelLoader(std::istream & levelInputStream):
factory(),
levelId(0),
levelInputStream(levelInputStream),
levelInputStreamDataOffset(levelInputStream.tellg())
{}
|
LevelLoader.cpp:29:0: invalid operands of types "std::istream*" and "LevelId" to binary 'operator>>': Documentation tells me you can use the >> operator of istream to "read" data from files. Why isn't this working?
Docs from C++.com:
http://www.cplusplus.com/reference/iostream/istream/operator%3E%3E/
Relevant code:
LevelLoader.h, line 19:
Full source:
http://kutcomputers.nl/wwcode/LevelLoader.h
typedef unsigned short LevelId;
LevelLoader.cpp, starting from line 28:
Full source:
http://kutcomputers.nl/wwcode/LevelLoader.cpp
1 2
|
LevelId levelCount;
this->levelInputStream >> levelCount;
|
...and some other errors, but I assume the other errors are the results of the errors above.
Screenshot of compile errors (I don't know how to copy/paste them from Xcode)
http://www.plaatjesupload.nl/bekijk/2010/09/12/1284320549-210.png
Full sourcecode:
http://kutcomputers.nl/wwcode/
Could someone explain me those errors?
Other suggestions/comments/feedback is also welcome.