5

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.

einpoklum
  • 118,144
  • 57
  • 340
  • 684
user1958486
  • 571
  • 3
  • 8

1 Answers1

7

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>;
user17732522
  • 53,019
  • 2
  • 56
  • 105