The type of the derived class in the template argument does not compile

This is a piece of code that I was hopelessly stuck in.

template <class T, T nt>
class C;

struct base{
   int i;
} b;

struct derived : base{} d;

C<base*,&d> obj;

Why does this give an error could not convert template argument &d to base*?

+5
source share
1 answer

When comparing an argument with a parameter that is a pointer / reference, the derivatives of the base transforms are not taken into account, even if the transforms are valid in other circumstances.

14.3 / 5 [Standard quote for reference only]

If the non-type template argument cannot be converted to the type of the corresponding parameter template, then the program is poorly formed.

....

- , (4.4) (4.2). [: , (4.10) , (4.10). 0 - - template-parameter . ]

+5

All Articles