Classes needing other undeclared classes
Hi there!
the problems simple:
Class A needs Class B, Class B needs Class C, and Class C need Class A
Example
class A
{
B *classb
}
class B
{
C *classb
}
class C
{
A *classb
}
its an infinite loop!
any ideas?
thanks - Yratelev
Yratelev
Hmmm...
extern class a;
extern class b;
extern class c;
EDIT:
Haha, sorry, read your question wrong
Okay, at the start of the header file (or .cpp file) where you define your classes, add this:
class a;
class b;
class c;
This is prototyping the classes; it works just the same as prototyping functions. You just tell the compiler that there is going to be a class a, class b and a class c, that will be defined later.
[edited by - Ronin_54 on October 8, 2002 2:21:52 PM]
extern class a;
extern class b;
extern class c;
EDIT:
Haha, sorry, read your question wrong
Okay, at the start of the header file (or .cpp file) where you define your classes, add this:
class a;
class b;
class c;
This is prototyping the classes; it works just the same as prototyping functions. You just tell the compiler that there is going to be a class a, class b and a class c, that will be defined later.
[edited by - Ronin_54 on October 8, 2002 2:21:52 PM]
Split your classes in different files and use forwards:
Edit: mhm, no need for different files
-----------------------
Header file for ClassA
-----------------------
class ClassB;
class ClassA {
ClassB* P;
// you cant inline ClassB functions
}
-----------------------
Source file for ClassA
-----------------------
#include "classb.h" // the other class
#include "classa.h"
// here you can use ClassB functions normaly
[edited by - Maverick the divider on October 8, 2002 2:24:27 PM]
Edit: mhm, no need for different files
-----------------------
Header file for ClassA
-----------------------
class ClassB;
class ClassA {
ClassB* P;
// you cant inline ClassB functions
}
-----------------------
Source file for ClassA
-----------------------
#include "classb.h" // the other class
#include "classa.h"
// here you can use ClassB functions normaly
[edited by - Maverick the divider on October 8, 2002 2:24:27 PM]
---Quite soon...ICQ: 163187735
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement