Assume that classa is overloaded with front and back ++, the form of the overload function should be as follows:
Classa & classa: Operator ++ () // front ++
{
Itsval ++;
Return * this;
}
Const classa: Operator ++ (INT) // post ++
{
Classa temp (* This );
Itsval ++;
Return temp;
}
Several of them can be studied:
1> to distinguish between the prefix and Postfix operators, you need to add the parameter "int" to the Postfix operator overload function, although this type does not represent any actual meaning except for the difference;
2> the prefix returns a reference to the variable, and the latter returns a constant. Therefore, ++ C is legal, while C ++ is invalid. This can be verified by using the basic data type ++ operation in VC 6.0 and Dev C ++;
3> Why not let C ++ be legal? If you want to implement C ++, you must make the post-return variable or variable reference. C ++ returns the C value first and then + 1, so it is impossible to return C, so we can only create local variables to save the initial values of C, then, return local variables (local variables do not allow returning references), but after returning local variables, if the next ++ operation is performed, the value of this local variable is involved in the calculation. Therefore, C ++ is equivalent to C ++ at this time, so it has no significance.