0

Suppose I have a header file as follows:

template <typename T>
class Foo
{
    template <typename U>
    int bar();

    template <typename U>
    int foobar();
};

I want to explicitly instantiate this class and all its methods to work with int, float and double types. Do I have to manually type out each instantiation or is there a better way to do this?

tersrth
  • 861
  • 6
  • 18
  • 2
    Yes, if you want to explicitly instantiate you have to list all instantiations. Why do you need explicit instantiation? The better way is to use implicit instantiation. – Thomas Sablik Jun 08 '20 at 07:44
  • An alternative would be to use SFINAE (`is_arithmetic_v`) to make it usable with those types only - but that wouldn't be explicit istantiation. – Ted Lyngmo Jun 08 '20 at 07:47

0 Answers0