lundi 29 juin 2015

Select enum type based on template parameter

I have a class:

template <class type>
class sysbase : public base
{
 public:
  static type* Spawn(int Config = 0) { … }
  … 
};

And about 50 enums in the global namespace:

enum a_config { A1, A2, … };
enum b_config { B1, B2, … };
etc.

Classes a, b, etc. (derived from sysbase) will be passed as the type template argument to sysbase.

Now I would like to change the Config parameter to be of one of those enum types instead of just a plain int to improve type safety, so that:

  • when type is class a, then the type of Config would be a_config
  • when type is class b, then the type of Config would be b_config
  • etc.

The enums should preferably stay in the global namespace to not break the existing code which uses e.g. a::Spawn(A1).

Is there a way to accomplish this?

Aucun commentaire:

Enregistrer un commentaire