Reputation: 10837
I need a pointer to my main class from a singleton class. The singleton class header is included in the main class.
In MainClass.cpp
mSingletonInstance->mMainClass = this;
To avoid a recursive inclusion problem I do not include my main class header in the singleton class, I just simply use a forward declaration of the main class.
In Singleton.h:
class MainClass;
class Singleton {
public:
MainClass *mMainClass;
};
The problem comes when I try to access a method from the main class... I get an incomplete type error.
In Singleton.cpp
Singleton::myMethod(){
mMainClass->someMethod(); // incomplete type error
}
The MainClass and Singleton are already defined when this happens...
Upvotes: 0
Views: 477
Reputation: 2914
Seems like you didn't include mainclass.h in singleton.cpp.
Upvotes: 1