I've been toying with a component-based system for a game, and I'm struggling a bit with the design of my component base class. My components will basically be data buckets with little to no functionality. The attributes every component will have include EntityID and TypeID. I would like to create a base component class with those two properties from which all specialized components will inherit. How can I prevent instantiation of the the base class with no methods to be made purely virtual?
enum ComponentType {
ATTR_HP
, ATTR_AC
, ATTR_STR
, ATTR_INT
};
class Component {
public:
Component(long entityID, ComponentType compType) : EntityID(entityID), TypeID(compType) {}
long EnityID;
int TypeID;
};
class CharAttribute : public Component {
public:
int Value;
int ValueMin;
int ValueMax;
};
I suppose I could make the EntityID and TypeID members private and then make the accessors pure virtual, but then I would pretty much have to repeat the same code in the implementation for every subclass.
What's the best way to make method-less base classes abstract?