Class template argument deduction - why does it fail here?

Viewed 192

Why does the following CTAD attempt fail to compile ?

template <typename T> struct C { C(T,T) {} };
template <> struct C<int> { C(int) {} };

C c(1);  //error: template argument deduction failure

I would have expected that the constructor C(int) would have been deduced.

1 Answers

Implicit deduction guides are only generated for constructors in the primary template, not for constructors of specializations.

You need to add the deduction guide explicitly:

C(int) -> C<int>;
Related