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 ++}
Comments
To leave a comment
C ++ (C plus plus)
Terms: C ++ (C plus plus)