Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Built-in operator candidates

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."

I am not sure about the intent of this quote from the Standard. Is it possible to define a user defined candidate function that has the same name and type as a built-in operator?

e.g. the below which is clearly wrong.

int operator+(int)

So what does this quote mean?

like image 749
Chubsdad Avatar asked Nov 09 '10 03:11

Chubsdad


1 Answers

Just pick one of those in 13.6. Like

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);

So

enum Kind { Evil, Good };
bool operator<(Kind a, Kind b) { ... }
like image 103
Johannes Schaub - litb Avatar answered Oct 18 '22 20:10

Johannes Schaub - litb