In the study of this part of some places do not understand, some are excerpted from the web materials.
1, overloaded operators have two forms, that is, overloading the member functions of the class and overloading the friend function for the class.
2, the member function can use only one parameter, the friend class must have two parameters, all operand passes through the parameter all.
3, ++i,--I, the former increment is the reference return, no parameter is the predecessor operation. The latter increment is the value returned, and the parameter in the post parameter is just an identity.
4, if you define an object Cuser user= (2) compilation can pass, then in order to construct the function of the automatic conversion function, you can use the explicit keyword before the constructor. Explicit can only appear in a constructor declaration within a class, only for one parameter. Then after using the explicit keyword Cuser user=2 the compilation fails, the standard cuser user (2) should be used to assign a value to the object.
5, when the overloaded function is a member function, the parameters of the binocular operator section can be written only one, the friend class must be all the parameters are written to be passed.
The operator overload function has two parameters, because the overloaded function is a member function in the complex class, and one argument is implied, and the operator function implicitly accesses the member of the object with the this pointer. One is a member of the object that the this pointer points to, and one is a member of the object in the formal parameter. This->real+c2.real,this->real is c1.real. After overloading an operator function with a member function, the C1+C2 compilation system interprets it as c1.operator+ (C2). That is, the operator overload function is called through the object C1. and takes the second argument in the expression (the class object C2 to the right of the operator) as a function argument.
6, implicit pointer, the object generated by the class will have a pointer to the object itself this, for example, said complex TS, when the TS object is created, will produce a complex *this=&ts, this pointer does not account for the object's memory, not user-defined, Does not occupy object memory, but is part of an object and is able to access the data and function members of the object. This is used implicitly by the use of function members or data members within a class. The compiler will do it by itself.
7, if there is a data member in the class int num, a member function is int add (int num), then the compiler does not know which NUM is passed over, then it needs to display the definition of this pointer, the function body {this->num+num;}, The first represents the member data in the class, and the second is the passed argument.
C + + Overloaded learning Notes