How do I avoid having to forward declare (and thus violating the DRY principle) given the following:
World.h
#include "Entity.h"
class Entity;
typedef std::shared_ptr<Entity> Entity_ptr;
typedef unsigned int entity_id;
class World
{
public:
void add_entity(Entity_ptr entity);
void remove_entity(entity_id entityId);
};
typedef std::shared_ptr<World> World_ptr;
Entity.h
#include "World.h"
typedef unsigned int entity_id;
class World;
typedef std::shared_ptr<World> World_ptr;
class Entity
{
public:
World_ptr world() const { return world_; }
void set_world(World_ptr world) { world_ = world; }
};
typedef std::shared_ptr<Entity> Entity_ptr;
Because each file depends on the other, neither can compile unless I forward declare the class and the typedef for the shared_ptr.
I've not coded with C++ in, oh, about eight years. So I'm a little rusty.
Thanks!