I am writing a game where a certain location will point to a creature which resides there and also the creature points to the location where it is located. I am running into problems however because when I declare the location class and add as one of its members a pointer to an as of yet undeclared class creature it gives me an error. Is there any way to make this work? I've rewritten the relevant code and posted it here.
So the problem basically is that I'm trying to create a pointer to a class that doesn't exist yet.
Anyone have any ideas?
Gives the error message:Code:#include <iostream> #include <string> #include <cstdlib> using namespace std; class location { public: int x; int y; creature *pCreature; // CLASS CREATURE IS AS OF YET UNDECLARED! // }newLocation; class creature { public: int health; int strength; location *pLocation; }dog; int main() { dog.pLocation = &newLocation; newLocation.pCreature = &dog; system("PAUSE"); return 0; }
Code:12 C:\Dev-Cpp\newTemp.cpp ISO C++ forbids declaration of `creature' with no type 12 C:\Dev-Cpp\newTemp.cpp expected `;' before '*' token



LinkBack URL
About LinkBacks


