| Pascal Bourguignon 2004-08-28, 3:57 pm |
| vertigo <none@microsoft.com> writes:
> Hello
> I have:
>
> classA.h file:
> #include "classB.h"
> classA{
> classB *ptr;
> };
>
> classA.c file:
> #include "classA.h"
> ......
>
> classB.h file:
> #include "classA.h"
> classB{
> classA *ptr;
> }
>
> classB.c file:
> #include "classB.h"
> ......
>
> I compile classA.c and classB.c and later link all together.
> My problem is that in this case there is redefinition of classA and
> classB (because classA.h and classB.h files are included two times).
> When i used in *.h files:
> #ifndef XXX
> #define XXX
> .....
> #endif
>
> *.h files are included once but i do not see their definitions and can
> not compile (classB.h do not see definition for classA and classA.h do
> not see definition for classB).
>
> How can i solve this problem ?
Use forward class declarations:
class classA;
class classB{
classA* ptr;
};
class classA{
classB* ptr;
};
--
__Pascal Bourguignon__ http://www.informatimago.com/
Our enemies are innovative and resourceful, and so are we. They never
stop thinking about new ways to harm our country and our people, and
neither do we.
|