为什么“A<0>=0"中的模板id由于大于或等于运算符“>="而不

2023-03-09C/C++开发问题
2

本文介绍了为什么“A<0>=0"中的模板id由于大于或等于运算符“>="而不能在没有空间的情况下编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

template 使用 A = int;void f(A<0=0);//试图声明一个函数 f 接受 int,//使用默认参数 0//按预期工作://void f(A<0> = 0);

这既不能在 GCC 4.9.2 或 Clang 3.5 上编译 - 更不用说 ICC 或 VC++.显然 >= 位被解析为大于或等于运算符.但是,这对于 [temp.names]/3 来说似乎是不正确的:

<块引用>

名称查找(3.4)后发现名称是模板名称operator-function-idliteral-operator-id 指的是一个集合重载函数的任何成员是函数模板,如果这后面跟着一个<<总是作为template-argument-list 并且从不作为小于运算符.解析模板参数列表时,第一个非嵌套>138 作为结束分隔符 而不是一个大于运算符.[..] [ 示例:

template类 X {/* ...*
The End

相关推荐

无法访问 C++ std::set 中对象的非常量成员函数
Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)...
2024-08-14 C/C++开发问题
17

从 lambda 构造 std::function 参数
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)...
2024-08-14 C/C++开发问题
25

STL BigInt 类实现
STL BigInt class implementation(STL BigInt 类实现)...
2024-08-14 C/C++开发问题
3

使用 std::atomic 和 std::condition_variable 同步不可靠
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)...
2024-08-14 C/C++开发问题
17

在 STL 中将列表元素移动到末尾
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)...
2024-08-14 C/C++开发问题
9

为什么禁止对存储在 STL 容器中的类重载 operator&amp;()?
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)...
2024-08-14 C/C++开发问题
6