I have a chunk of code that keeps failing on me no matter how much I thin it down. The code in question is:
#include <iostream>
class Tile;
class Tile{
public:
void PRINTME();
};
void Tile::PRINTME() { std::cout << "Blergh"; }
Tile Wall;
Wall.PRINTME();
It displays the following error message:
(...)\MapTiles.h|11|error: 'Wall' does not name a type|
I might be relatively new to C++ programming, but a couple of hours of digging around Stackexchange and tutorials on classes tells me that the above snippet should run.
Multiple other such problems here have been solved using forward declarations, but in this case it is trying to read the object "Wall" as a class. As the class was previously quite a bit larger, I trimmed it considerably yet it still fails to work decently. I based this example off the Tutorialspoint tutorial on C++ classes and member functions.
I'm using MinGw that comes with Code::Blocks 13.12, on a Windows 7 (64bit) machine with the compiler flag -std=c++11
ticked.
Aucun commentaire:
Enregistrer un commentaire