So I have two classes, EntityList and Entity.
EntityList comes first and requires Entity in some of it's functions.
Entity comes second and requires EntityList in some of it's functions.
But this isn't working for me since the first class can't access it because to it the second class 'Entity' hasn't even been made yet.
Any tips?
put "class Entity;" above the EntityList class.
Initialize them both before using them. Unless the constructors of both need the other class, in that case what are you doing don't do that.
Would defining an empty base class then making Entity and EntityList subclasses of the base work?
[QUOTE=Mattz333;21388280]Would defining an empty base class then making Entity and EntityList subclasses of the base work?[/QUOTE]
That has nothing to do with this.
Heavy 'n' Medic
[cpp]class EntityList;
class Entity;
class EntityList {
public:
Vector<Entity> Ents;
};
class Entity {
public:
void Soemthing(EntityList*);
};[/cpp]
Declare the classes before you define them. It works for classes just like it works for variables and functions.
Not that Entity should be knowing anything about EntityList to begin with.
[QUOTE=jA_cOp;21388914]Not that Entity should be knowing anything about EntityList to begin with.[/QUOTE]
This.
And BTW, forward-declaration will only work for pointers/references.
The only reason I have Entity communicating with EntityList is so an Entity can add itself to the EntityList.. But thinking about it now, there are better ways to go about that.
Sorry, you need to Log In to post a reply to this thread.