从默认参数中推导模板参数

And*_*zos 1 c++ c++11

为什么这个C++ 11程序不起作用:

template <typename T>
void f(T t = 42) {}

int main() { f(); }
Run Code Online (Sandbox Code Playgroud)

为什么不能T从默认参数中推断出来42

eca*_*mur 5

14.8.2.5 [temp.deduct.type]:

19 - 无法从函数默认参数的类型推导出模板类型参数.[...]

给出的示例与您的示例基本相同.