Solved

why INT in postfix overloading

Posted on 2002-04-08
4
263 Views
Last Modified: 2010-04-02
I was wondering why in C++ when you overload an operator for postfix operations that it takes in an INT?

Would it makes sence to create a command such as POST to take in?  Thanks.
0
Comment
Question by:sarniscool
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 9

Expert Comment

by:jasonclarke
ID: 6927593
It is just a dummy parameter, as you are no doubt aware, to differentiate between postfix and prefix.

One of the basic design goals of C++ was to avoid unnecessary new keywords (although in this case Bjarne Stroustrup states that he would actually have preferred new keywords).

This led to the use of this convention, which is, as you imply a bit of a language wart.

If you want to find out more, read the Design & Evolution of C++ (by Bjarne Stroustrup), section 11.5.3.
0
 

Author Comment

by:sarniscool
ID: 6929838
Is that it?  No special reason other than to differentiate?  Why INT out of all the other C++ keywords?
0
 
LVL 9

Accepted Solution

by:
jasonclarke earned 50 total points
ID: 6930747
Nothing really... all Bjarne Stroustrup has to say is:

'...Other unary operators are prefix and take no arguments when defined as member functions.  The "odd" and unused dummy int argument is used to indicate the odd prefix operators.  In other words, in the postfix case, ++ comes between the first (real) operand and the second (dummy) argument and is thus postfix."

it is purely a convention, for no real reason.... BS states he would have preferred 'prefix' and 'postfix' keywords.
0
 

Author Comment

by:sarniscool
ID: 6934729
alright, thanks
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question