title: C++ class factory macro
body: <p>I would like to make a macro to easily create new Classes that derive from the same base class with different name and slightly different behavior.</p>
  
  <p>I already have  </p>
  
  <pre><code>class FactoryBonusModifier
  {
  public:
     /// Function to overload
     virtual BonusModifierAbstract* createBonus() const = 0;
  protected:
  };
  
  #define DEFAULT_BONUS_FACTORY_DECLARATION(FactoryName)      \
  class Factory## FactoryName : public FactoryBonusModifier   \
  {                                                           \
  public:                                                     \
      virtual BonusModifierAbstract* createBonus() const;     \
  };
  
  #define DEFAULT_BONUS_FACTORY_IMPLEMENTATION(FactoryName)                 \
      BonusModifierAbstract* Factory## FactoryName::createBonus() const    \
      {  return new FactoryName();  }
  
  
  DEFAULT_BONUS_FACTORY_DECLARATION(BonusModifierGoThroughWall);
  </code></pre>
  
  <p>and the implementation part writen in the cpp.</p>
  
  <p>I want to know if I can have a macro that would build an enum and an array of these new classes with as little copy/paste possible.</p>
  
  <p>In the end I want to have something like</p>
  
  <pre><code>enum BonusType{
  Bonus1,
  Bonus2,
  ...,
  Nb_Bonus
  };
  
  FactoryBonusModifier* factories[Nb_Bonus] = 
  {
      new FactoryBonus1(),
      new FactoryBonus2(),
      ...,
  }
  </code></pre>