c++ - 内置运算符候选人

标签 c++ built-in overload-resolution candidate

C++03 $13.6/1- "[...]If there is a user-written candidate with the same name and parameter types as a built-in candidate operator function, the built-in operator function is hidden and is not included in the set of candidate functions."

我不确定从标准中引用这句话的意图。是否可以定义与内置运算符具有相同名称和类型的用户定义候选函数?

例如以下显然是错误的。

int operator+(int)

那么这句话是什么意思?

最佳答案

只需在 13.6 中选择一个即可。喜欢

For every pointer or enumeration type T, there exist candidate operator functions of the form

bool operator<(T, T);
bool operator>(T, T);
bool operator<=(T, T);
bool operator>=(T, T);
bool operator==(T, T);
bool operator!=(T, T);

所以

enum Kind { Evil, Good };
bool operator<(Kind a, Kind b) { ... }

关于c++ - 内置运算符候选人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4130335/

相关文章:

c++ std::getline/std::sort 没有按预期工作

Python id(obj) 临时更改

python - python 中除了 None 之外的其他唯一实例对象?

java - 如何在 Java/Swing 中实现内置编译器?

c++ - 为什么编译器不能决定在没有引用运算符的情况下调用哪个函数?

c++ - MONGODB C++ DRIVER mongocxx 和 legacy 的区别

c++ - 将 typedef 方法作为指针函数传递

C++ ASIO 驱动设置

c# - 使用泛型类型参数时有歧义的方法重载

c++ - 涉及旧式枚举和整数类型的重载解析