类模板参数推导-为什么它在这里失败



为什么以下CTAD尝试编译失败?

template <typename T> struct C { C(T,T) {} };
template <> struct C<int> { C(int) {} };
C c(1);  //error: template argument deduction failure

我本以为构造函数C(int(会被推导出来。

隐式推导指南只为主模板中的构造函数生成,而不为专业化的构造函数生成。

您需要明确添加扣除指南:

C(int) -> C<int>;

最新更新