You get a bonus - 1 coin for daily activity. Now you have 1 coin

3.3. Overloading operations ++ and - increment and decrement

Lecture



Unary increment ++ and decrement operators exist in two forms: prefix and postfix. The modern C ++ specification defines a way in which the compiler can distinguish between these two forms. In accordance with this method, two versions of the functions operator ++ () and operator— () are specified. They are defined as follows:

Prefix form:

operator ++ ();

operator— ();

Postfix form:

operator ++ (int);

operator— (int);

Specifying the int parameter for the postfix form does not specify the second operand, but is used only to distinguish it from the prefix form.

Example

class person

{int age;

...

public:

...

void operator ++ () {++ age;}

void operator ++ (int) {age ++;}

};

void main ()

{class person jon;

++ jon; jon ++}

created: 2015-12-20
updated: 2026-03-08
306



Was this answer useful?
Choose a quick rating so we can improve the next answer for you.
How satisfied are you?


Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "C ++ (C plus plus)"

Terms: C ++ (C plus plus)