Solved

why INT in postfix overloading

Posted on 2002-04-08
4
256 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 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now