Solved

why INT in postfix overloading

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ assignment question 7 236
FMX enumerated colours 2 115
I could not build boost code, 10 95
FMX TCameraComponent Problem 2 84
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

860 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