jeudi 26 mai 2016

template subclassing with partial specialization

Consider the following

template<typename Type, size_t Dimensions> 
struct Base 
{  
     Base(/*some args*/)  {   /*do something*/  }
};

template<size_t Dim>
class Derived : Base<double,Dim> {};

Derived doesn't inherit the constructor of the Base because it suggests that Base is a partial specialization and therefore requires some different constructor. However this is not so in my case. I mainly want it to have different name in different situations. I'm looking for a solution different than macros or the following one, if exists.

template<size_t Dim>
struct Derived
{
  typedef Base<double, Dim> Type;
}

mainly because I don't like using

Derived<n>::Type 

everywhere and not sure I want to

typedef Derived<n>

for every n I use.

Aucun commentaire:

Enregistrer un commentaire