Turn from: 45222905
return * this
#include <iostream>using namespacestd;classtest{ Public: //constructor FunctionTest (intI=0,Doublej=0.0): M_i (i), M_j (j) {}//Assignment Constructorstest&operator= (Test &RHS) { This->m_i =rhs.m_i; This->m_j =Rhs.m_j; return* This; } intm_i; DoubleM_j;}; intMain () {//1, assign the initial value, Output 1 2.3Test Obj1 (1,2.3); cout<< obj1.m_i << Endl << obj1.m_j <<Endl; cout<< Endl <<"-------------------"<<Endl; //2, the initial value is not assigned, output 0 0Test Obj2; cout<< obj2.m_i << Endl << obj2.m_j <<Endl; cout<< Endl <<"-------------------"<<Endl; //3, the initial value is not assigned, but the assignment constructor is assigned to the initial value , but attention is repeated call assignment constructor assigns the initial value. Test obj3; Obj3= Obj2 = Obj1;//here, the advanced obj2 = Obj1 operation, (after the assignment succeeds through return *this, returns the Obj2 object), and then the operation obj3 = Obj2. cout<< obj2.m_i << Endl << obj2.m_j <<Endl; cout<< Endl <<"-------------------"<<Endl; /** * * Through Example 3, you will find that if there is no return * This, you can not go back to the Obj2 object, then in the obj3=obj2 operation, the assignment constructor will not be used. C + + to make it easier for us to use an assignment like int i=j=k=5, you must return the object each time an assignment is performed in a right-to-left assignment, and then proceed to the left. *****/ return 0;}
There is another good explanation: 22220777
About C + + return * This