6

I have 2 template classes and one inherit from the other.

template <class T>
class X {
    public:
    int get() { return 1; }
};

template <class T>
class B : public X<T> {};

// Force B instantiation would expect X to be forced as well
template class B<int>;

// If I remove next line, no code is emitted for X
template class X<int>

When forcing the template instantiation of B, the X is not instantiated as well ( see https://godbolt.org/z/3vvenM8j4)

What is the reason for that?

Note: This is a follow up to how to force instantiation of a template class used with a type alias

I would expect the given solution to work but is does not

OznOg
  • 4,440
  • 2
  • 26
  • 35

0 Answers0