1

I thought that template classes were only compiled if instantiated.

Consider, in a source file,

template<unsigned N>
class wumpus
{
    enum {value = N};
};

template<>
class wumpus<0>
{
    static_assert(false, "Why am I being compiled?");
};

The compiler "evaluates" the static_assert yet the (full) specialisation is not being instantiated anywhere.

I thought I'd only get an assertion if I declared wumpus<0> w; somewhere. What is going on?

P45 Imminent
  • 8,319
  • 4
  • 35
  • 78

0 Answers0