| | |
operator overload
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
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?
Views: 1594 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






