【发布时间】:2021-05-18 14:20:43
【问题描述】:
不知道为什么这段代码不能编译:
struct S{ int m; };
template<class T, class = std::enable_if_t<std::is_same_v<T, S>>>
T& operator+=(T&& arg0, int arg1)
{
arg0.m += arg1;
return arg0;
}
int main()
{
S val0{ 0 }; int val1{ 1 };
val0 += val1;
return 0;
}
但是,当 SFINAE 被移除或使用基本整数而不是结构时(通过适当的模板代码更改),它确实可以编译。
【问题讨论】:
标签: c++ function templates sfinae enable-if