Like I would want to do something like this,
class Object {
public:
World * Parent_World; //This here
Object(World * Parent_World=NULL) : Parent_World(Parent_World) {}
};
class World {
public:
Object * Objects = new Object[100];
}
That doesn't work because of the order. And I can't just simply define world earlier because I want also to have access to class Object from the World
Make a forward declaration before Object:
class World; //Now you can use pointers and references to World
class Object {
public:
World * Parent_World; //This here
Object(World * Parent_World=NULL) : Parent_World(Parent_World) {}
};
class World {
public:
Object * Objects = new Object[100];
}
Making a forward declaration gives a compiler enough information to deal with pointers and references to the type being declared
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With