I have an abstract class
template <class T> struct A { };
and several specific derived classes with various constructors
// The constructor of B takes 1 input template <class T> struct B : public A<T> { B() { /* default ctor */ } B( T *input ) { /* initializer */ } // .. implement virtual methods } // The constructor of C takes 2 inputs template <class T> struct C : public A<T> { double some_member; C() { /* default ctor */ } C( T *input, double& value ) { /* initializer */ } // .. implement virtual methods }
I created a Factory that returns pointers to A , and I'm trying to use Variadic templates to forward input to the constructor of the selected derived class. It works fine, but I had to duplicate the code for cases with / without constructor inputs, and I'm looking for a way to prevent code duplication (see below).
template <class T> struct A_Factory { typedef std::shared_ptr<A> out_type;
Too bad a long question. Any suggestion to make it shorter appreciated.
c ++ c ++ 11 factory-pattern variadic-templates
Sheljohn
source share