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/