0

I have a similar problem to this but not the exact.

Assuming we have 2 header files and a main.cpp. In the first header file we have :

  namespace Logic
  {
    class GameManager;
  }

In the second header:

#include "first_header.h"
class Logic::GameManager 
{
public : 
    void init();
    void run():
};

And in the main.cpp i have :

#include "first_header.h"
int main()
{
   Logic::GameManager gm;
   gm.init();
   gm.run();
}

I get this error until i include the second header in main.cpp :

'gm' uses undefined class 'Logic::GameManager'

-Is this way of using namespaces and classes correct ?

-Is there a better way to do this?

Thanks.

Community
  • 1
  • 1

1 Answers1

1

Re-open the namespace to define the class.

namespace Logic {

class GameManager 
{
public : 
    void init();
    void run():
};

}

And include the second header, not the first, from main.cpp. The compiler cannot find the class definition unless it is directly #include'd.

Potatoswatter
  • 134,909
  • 25
  • 265
  • 421