user1958486
user1958486

Reputation: 569

Class template argument deduction - why does it fail here?

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.

Upvotes: 5

Views: 567

Answers (1)

user17732522
user17732522

Reputation: 76628

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>;

Upvotes: 7

Related Questions