Overloading same operator multiple times

Aug 10, 2015 at 6:02pm
Hi, I just wanted to know how overloading same operator multiple times works and how does the compiler know which overloaded definition is called in.
P.S: Couldn't find anything on google.

Thank you!
Last edited on Aug 10, 2015 at 6:03pm
Aug 10, 2015 at 6:17pm
how overloading same operator multiple times works
As with any function. Operators are just syntax sugar for function calls.

So if you have something like
1
2
3
foo x;
bar y;
x + y;

Compiler would look for function named operator+ which can take arguments of type foo and bar.
Aug 10, 2015 at 6:25pm
An overloaded operator is a function (albeit with a special syntax).
The rules for function overload resolution apply.

See: http://en.cppreference.com/w/cpp/language/overload_resolution
Note: see 'Call to an overloaded operator' on how the set of candidate functions is formed.
Last edited on Aug 10, 2015 at 6:41pm
Aug 10, 2015 at 6:32pm
@JLBorges: you have a stray apostrophe at the end of the link.
Aug 10, 2015 at 6:40pm
Thanks. Removing it now.
Aug 11, 2015 at 10:38am
Thank You very much!
Topic archived. No new replies allowed.