Sure, this no Irrlich specific question but due to the good experience with the community I post this in the hope of a hint.
Situation:
I've two classes (classA and classB) Both are implemented in a cpp file and both having a header file.
Further more is classA using classB and vice versa. To accomplish this I need to include classA.h in classB.h and vice versa.
But this means to set up an eternal "include-loop" between the two headers.
Consequently my compiler (VC2003) is not very amused about this try.
I've tried a lot (even browsing a book about C++) but without success.
The A-uses-B and B-uses-A situation isn’t so odd, isn’t it?
So my question:
How to deal with such a situation?
Thanks
Thorsten
#include drives me crazy
thats exactly my problem and i dont know how to do it, i guess its not possible so easily.
maybe like this:
class A:
include class B and make an instance of it, then use the data
class B: derrive from class A and use the data
ps: i head its not possible this problem and some timing problems with irrlicht are driving me crazy (i just want a simple sprite to move up 1.0f per tick, this damn #+!%$ is not possible outside the while(IrrlichtDevice->run()) mainloop, isnt it?!!! )
its really demotivating and frustrating
maybe like this:
class A:
include class B and make an instance of it, then use the data
class B: derrive from class A and use the data
ps: i head its not possible this problem and some timing problems with irrlicht are driving me crazy (i just want a simple sprite to move up 1.0f per tick, this damn #+!%$ is not possible outside the while(IrrlichtDevice->run()) mainloop, isnt it?!!! )
its really demotivating and frustrating
Try adding the following to your header files:
Code: Select all
#pragma once
"Object-oriented programming is an exceptionally bad idea which could only have originated in California."
- E.W. Dijkstra
- E.W. Dijkstra
Try a forward declaration like this
This way you can easily separate the necessary files.
Code: Select all
class A;
class B {
A* useClassA;
}
class A {}
The forward declaration was the solution (at least in my small model app) I didn't know that this is also possible for classes.
The #define and #pragma once approaches (I've tried them the days before) lead me into a situation, that one of the class was undefined (since the headers was only used once in both cases)
@All: Thanks for the fast replies, I stood on the edge of madness because of this
Thorsten
The #define and #pragma once approaches (I've tried them the days before) lead me into a situation, that one of the class was undefined (since the headers was only used once in both cases)
@All: Thanks for the fast replies, I stood on the edge of madness because of this
Thorsten