Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

why INT in postfix overloading

Posted on 2002-04-08
4
Medium Priority
?
266 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
  • 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 200 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

971 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