0

What I want to doe is a simple conditional inheritance in the Foo class so depending on how it's instanciated (see usage)

class BaseType
{
  protected:
  m_valueX;
  public: BaseType(int param = 0):m_valueX(param){}
  ~ BaseType(){}
 }

...

 class Type1 : public BaseType
 {
  public: Type1():BaseType(1){}
  ~Type1(){}         
 }

...

 class Type2 : public BaseType
 {
  public: Type2(): BaseType(2){}
  ~Type1(){}         
 }

...

 template<typename Base>
 class Foo: public Base
 {

  public:
  Foo(){}
  ~Foo();
  void dothis();
  }

...........

in cpp file

template<typname Base>
Foo<Base>::Foo():Base()
{
}

Foo::~Foo(){}

void Foo::dothis(){}

usage:

Foo* fooptr1 = new Foo<Type1>();<== error use of class template requires template argument list
Foo* fooptr2 = new Foo<Type2>();>();<== error use of class template requires template argument list

Thank you!

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
Bayo Alen
  • 341
  • 1
  • 6
  • 13

1 Answers1

3

Foo is a template, not a class. The common class type for all Foo<T> is Base, so you can say:

Base * p1 = new Foo<Type1>;
Base * p2 = new Foo<Type2>;
Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
  • ok I see your point thank you very much. but this answer from another post does is for my current problem. http://stackoverflow.com/questions/13779938/conditionally-inheriting-from-either-of-two-classes – Bayo Alen Dec 18 '13 at 21:59