0

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...

Pier
  • 10,298
  • 17
  • 67
  • 113

1 Answers1

1

Seems like you didn't include mainclass.h in singleton.cpp.

Dmitriy Kachko
  • 2,804
  • 1
  • 19
  • 21