+ + increments each have pre-increment and post-increment differences, while overloaded operators, although the function names are the same, there should be a corresponding difference. The result of the increment operator before an integer variable is the same as the return value variable, and then the increment operator returns a temporary variable. It is also necessary to differentiate between the pre-increment and the post-increment when the increment operator overloads.
The pre-Increment action object is the same variable as the returned object, which requires that the argument be a reference to the object, and the return value is also a reference to the object when the first increment of the reaction object:
classname& operator++ ();//pre-increment operator set to class member function
Friend classname& operator++ (classname&a);//Pre-increment Fu set to class friend function.
The subsequent increment character also requires that the argument be a reference, because the arguments in the call are changed, but in order to differentiate from the previous increment, C + + provides a technical process:
ClassName operator++ (int);//post-volume operator set to class member function
Friend ClassName operator++ (className &a,int i); The friend function, after the call increment character violates the function parameter matches the general, but the compiler specially does the special processing.
For flow operators. Because the stream operator predecessor object parameter is Ostream&out, it is not an object of that class, so it cannot be set as a member function of a class, must be set to a friend function, and a friend function is not a member function of a class, but what is special about him is that he can access the private members of the class. So the operator overload of the stream must be declared as a friend function, such as friend ostream& operator (Classname&a);
Overloading of increment operators