Why declare the class that you included as a header file?
#include "TreeCallObj.h"
#include "TreeDevObj.h"
#include "TreeDevCallObj.h"
class TreeCallObj; //what is the purpose of this line ?
class TreeDevObj; //what is the purpose of this line ?
class TreeDevCallObj; //what is the purpose of this line ?
class Apple
{
public:
...
private:
...
}
Consider this:
Now you try to include one of the files in a different one, say you
#include "a.h".The compiler will parse it as:
fine –
A_Hisn’t definedtry to paste the contents:
ok, since
B_Hisn’t definedthis will not define
A, becauseA_His defined. So next, we havewhich will lead to an error, because
Awasn’t defined or declared before the use.The forward declaration fixes this.
Of course, the best solution to this is to not include at all (unless you absolutely have to).