use*_*486 5 c++ template-specialization template-argument-deduction ctad
为什么以下 CTAD 尝试无法编译?
template <typename T> struct C { C(T,T) {} };
template <> struct C<int> { C(int) {} };
C c(1); //error: template argument deduction failure
Run Code Online (Sandbox Code Playgroud)
我本以为构造函数 C(int) 会被推导出来。
隐式推导指南仅为主模板中的构造函数生成,而不为特化的构造函数生成。
您需要显式添加推导指南:
C(int) -> C<int>;
Run Code Online (Sandbox Code Playgroud)