   Good practice with class inheritance, c++
  I've created a base class "unit" from which I had planned to derive something along the lines of say cavalry, infantry and artillery.  However, the way I've written "unit" means that the sub classes won't have any new or unique methods or variables - they'd simply initialise variables to different amounts in the constructor.With this being the case, should I do away with the sub-classes altogether, and maybe just have a switch statement inside the unit constructor which could be fed an integer so it knows what type of unit is being created?  I get the feeling I might have planned inheritance here more as a "to show I can" than as something that's actually necessary.Thanks   
  Unless the derrived classes add something to the base class that makes it a unique unit i would move away from inheritance and just store a variable in the old base-class that identifies that characters role.   ;  If the units' difference can be expressed only through parameterization, then of course you don't need explicit subclasses. However, don't have the switch inside the constructor. If your class Unit is as generic as you describe, it would be a shame to limit it that way. You can simply create a function for each different type of unit you are going to use:class Unit{  public:    Unit(int x,int y,int z)    {   ...    }};Unit* CreateCavalry(){  return new Unit(1,2,3);}Unit* CreateInfantry(){  return new Unit(2,4,5);};  You are right that subclasses are useless here. I would suggest to provide the constructor with an object which provides all the required data:struct unit_data { int health; float speed; };const unit_data &infantry(){  static const unit_data data = { 5, 10.0f };  return data;}const unit_data &cavalry(){  static const unit_data data = { 10, 50.0f };  return data;};class unit{  int health;  float speed;public:  unit(const unit_data &data) : health(data.health), speed(data.speed) {}};unit horseman(cavalry());unit pikeman(infantry());;  I have two types.  Unit represents an actual unit.  UnitType represents its type (cavalry, archer, etc...)  Every Unit holds a pointer to its UnitType.  The UnitType is passed as a parameter to the constructor.   ;Quote:Original post by GlakI have two types.  Unit represents an actual unit.  UnitType represents its type (cavalry, archer, etc...)  Every Unit holds a pointer to its UnitType.  The UnitType is passed as a parameter to the constructor.The way you just described it, it almost sounds like UnitType could be an enum.  enum UNITTYPE{CAVALRY,ARCHER,//and on and on};Or did I miss something?;Quote:Original post by Chad SmithQuote:Original post by GlakI have two types.  Unit represents an actual unit.  UnitType represents its type (cavalry, archer, etc...)  Every Unit holds a pointer to its UnitType.  The UnitType is passed as a parameter to the constructor.The way you just described it, it almost sounds like UnitType could be an enum.  enum UNITTYPE{CAVALRY,ARCHER,//and on and on};Or did I miss something?I think the unit type also holds the units fighting statistics, movement speed, max health, etc. Individual unit instances probably have current health, movement used, etc.   