struct A {};
template<typename T>
void f(int n, T m = 3.14159)
{}
int main()
{
f(8, A{}); // ok
f(8); // error: no matching function for call to 'f'
}
参见 online demo
为什么默认参数在模板函数中不起作用?
编辑:我也试过跟随,想知道为什么它不起作用。
void g(int, auto = 3.14159)
{}
最佳答案
默认函数参数不影响模板参数推导。
您还需要模板参数的默认参数:typename T = double
。
至于void g(int, auto = 3.14159)
,好像没办法修复了。
https://stackoverflow.com/questions/68040354/
相关文章:
flutter - flutter中的flutter build bundle和appbundle有
flutter - Flutter 中 colorScheme 和 ThemeData 声明的原色
react-native - SectionList React Native 上的粘性 heade
c++ - 无法将 'v8::MaybeLocal
kotlin - 如何在 Kotlin Exposed 中获取插入的行?
reactjs - 难以创建基本线(@react-three/fiber 和 Typescript)
delphi - Spring4D TDistinctIterator