0

Assume the snippet below. How can I replace the duplicate:

template<>
ClassB<ClassA<float> >::ClassB() {}

template<>
ClassB<ClassA<int> >::ClassB() {}

And replace this for one? I want to place this in the CPP file so not header:

I tried:

template<>
ClassB<ClassA<> >::ClassB() {}

And:

template<typename T>
ClassB<ClassA<T>>::ClassB() {}
template<typename B>
class ClassA {
public:
  B member;
  void call() {}; 
};

template<typename A>
class ClassB { 
   A a;
   public:
       ClassB();
       void call() { a.call();};
};

template<>
ClassB<ClassA<float> >::ClassB() {}

template<>
ClassB<ClassA<int> >::ClassB() {}

int main() { 
  ClassB<ClassA<float> > b;
  b.call();
}
robert
  • 1,921
  • 2
  • 17
  • 27
  • "I want to place this in the CPP file so not header:" -> https://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file – 463035818_is_not_an_ai Jul 01 '22 at 16:03
  • Hidind template defintions to .cpp files requires you to know the full set of supported arguments in advance. Are yours just `int` and `float`? – HolyBlackCat Jul 01 '22 at 16:04

0 Answers0