| | |
operator overload
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2008
Posts: 15
Reputation:
Solved Threads: 0
Hi
when I look at this website http://www.parashift.com/c++-faq-lit...erloading.html,
I don't quite understand for the section 13.14 about prefix++ and postfix++.
Number x = /* ... */;
++x; // calls Number::operator++(), i.e., calls x.operator++()
x++; // calls Number::operator++(int), i.e., calls x.operator++(0)
why ++x is calling x.operator++() while x++ is calling calls x.operator++(0)?
when I look at this website http://www.parashift.com/c++-faq-lit...erloading.html,
I don't quite understand for the section 13.14 about prefix++ and postfix++.
Number x = /* ... */;
++x; // calls Number::operator++(), i.e., calls x.operator++()
x++; // calls Number::operator++(int), i.e., calls x.operator++(0)
why ++x is calling x.operator++() while x++ is calling calls x.operator++(0)?
This is the important part:
In other words, if one didn't have a dummy int, there'd be no way to disambiguate them.
•
•
•
•
Since the prefix and postfix ++ operators can have two definitions, the C++ language gives us two different signatures. Both are called operator++(), but the prefix version takes no parameters and the postfix version takes a dummy int.
"Technological progress is like an axe in the hands of a pathological criminal."
All my posts may be freely redistributed under the terms of the MIT license.
All my posts may be freely redistributed under the terms of the MIT license.
•
•
•
•
Number x = /* ... */;
++x; // calls Number::operator++(), i.e., calls x.operator++()
x++; // calls Number::operator++(int), i.e., calls x.operator++(0)
That IS the overload method.
As they say: "It is what it is."
You looked it up, NOW YOU KNOW...
"I like beating by head against the wall because it feels so good when I stop"
![]() |
Similar Threads
- copy constructor & assignment operator overload problems (C++)
- operator() (C++)
- C++ Tic Tac Toe using classes & operator overloading (C++)
- subtraction operator overload (C++)
- syntax error? .. operator overload method problemo (C)
- How to overload subscript operator? (C)
Other Threads in the C++ Forum
- Previous Thread: simple question regarding array
- Next Thread: How to delete a folder?
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






