cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
Overloading same operator multiple times
Overloading same operator multiple times
Aug 10, 2015 at 6:02pm UTC
NPcomplete
(174)
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 UTC
Aug 10, 2015 at 6:17pm UTC
MiiNiPaa
(8886)
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 UTC
JLBorges
(13770)
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 UTC
Aug 10, 2015 at 6:32pm UTC
MiiNiPaa
(8886)
@
JLBorges
: you have a stray apostrophe at the end of the link.
Aug 10, 2015 at 6:40pm UTC
JLBorges
(13770)
Thanks. Removing it now.
Aug 11, 2015 at 10:38am UTC
NPcomplete
(174)
Thank You very much!
Topic archived. No new replies allowed.