C++: How to use types that have not been defined?
- by Jen
C++ requires all types to be defined before they can be used, which makes it important to include header files in the right order. Fine. But what about my situation:
Bunny.h:
class Bunny
{
...
private:
Reference<Bunny> parent;
}
The compiler complains, because technically Bunny has not been completely defined at the point where I use it in its own class definition.
This is not sufficient:
class Bunny;
class Bunny
{
...
private:
Reference<Bunny> parent;
}
Apart from re-writing my template class Reference so it takes a pointer type (in which case I can use the forward declaration of Bunny), I don't know how to solve this.
Any suggestions?