c++ - 模板代码中的默认类型参数错误

标签 c++ templates

1)template <class T = int, class U = double> //compiles

2)template <class T, class U =double> //compiles

3)template <class T = int, class U> //fails

为什么 1 和 2 可以编译而 3 不能?

最佳答案

出于同样的原因:

void f(int = 0, int);

失败。

无法使用第 3 版默认参数:

template<class T = int, class U> class B { ... };

B<, short> var; // ??? no such syntax

关于c++ - 模板代码中的默认类型参数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3824144/

相关文章:

c++ - 如何在 gtk 中设置包含宽字符的文本?

c++ - 在构造函数调用中出现错误 C2512

c++ - 使用具有部分类特化的 CRTP?

c++ - CMake编译器未设置

c++ - 为什么我不能将 cend() 和 cbegin() 传递给 count_if?

c++ - Memset 枚举数组值设置不正确 (C/C++)

templates - 在模板上迭代 golang 中的嵌套结构

c++ - 使用自由模板参数传递模板类型名

c++ - 模板类继承

c++ -::c++ 中模板函数调用前的作用域解析运算符