Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

rekursive include 1

Status
Not open for further replies.

DerStephan

Programmer
Aug 19, 2003
54
DE
Hi,

i have a little problem...
I have 2 classes in seperate cpp files with header files. Maybee classA and classB
classB carries an instance of classA

...
class classB
{
public:
classA memCA;
}
...

now what I want is a pointer on classB in classA
class classA
{
public:
classB* mempCB;
}
...

now the funny problem with the including of each others headerfile... I have in each haeder something like

#include "classB.h"
#ifndef _classA
#define _classA
class classA
...
#endif

and for classB the other way around.

I don't know what to do to prevent this all from rekursive including, this problem drives me crazy.

Any suggestions?

Thanks in advance

Stephan

PS: I really need to have this pointer...
 
You just need to declare the class without defining it to let classA know that it exists. At the top of classA.h, just add the line "class classB;" before you define classA. Then go ahead and #include the actual classb.h file in the classA.cpp file. This should fix the problem.
 
Just a prototyp class.

I think that will work.

Thanks for that prompt reply!!!
 
But look at your design, its not really good to have a referencing B when B references A
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top