Hi everyone,
I'm doing a little project after a long period of no c++, so please forgive me for any possible stupid mistakes.
Basically I have 2 cpp files, in first.cpp I define namespace 'myNS', and in second.cpp I define class 'myClass'. The problem is that I have a pointer of type myClass* in the namespace, and I need variables from the namespace in the myClass. So the 2 files look something like this:
//first.cpp
#ifndef FIRST_CPP
#define FIRST_CPP
#include "second.cpp"
namespace myNS
{
myClass* myClassPtr;
int justAnyNumber;
}
#endif
//second.cpp
#ifndef SECOND_CPP
#define SECOND_CPP
#include "first.cpp"
class myClass
{
public:
myClass()
{
myNS::justAnyNumber = 5; // Error here
}
}
#endif
When I compile this code I the error "myNS has not been declared". Now I understand that in this structure, the compiler/linker is trying to compile second.cpp before is reaches the definition of the namespace, but I'm still clueless on how to solve this issue.
Any ideas on how to solve this?