using namespace std;
Class A {
Public:
int val;
Int c;
A (int n=0, int cc=1) {
Val=n;
C=cc;
}
A& GetObj1 () {
//cout & lt; <"Ha, ha, ha;
Return * this;
}
Int getObj2 () {return val. }
};
Int main ()
{
(2), A A, b c [2]={2, 3};
Cout & lt;
Cout & lt;
}
Atul gawande etObj1 ()=5;
Why is this a word can change the value of Dr. Al?
CodePudding user response:
Are you the compiled without errors and warnings?CodePudding user response:
This kind of writing itself is right, because the integer 5 by constructor implicitly converted to AAtul gawande etObj1 ()=5; Equivalent of al-qeada etObj1 ()=A (5);
Sometimes this translation is not in conformity with the actual logic, to avoid this kind of transformation needs to use explicit keywords, the following
explicit A (int n=0, int cc=1) {
Val=n;
C=cc;
};
CodePudding user response:
Getobj1 returns the reference, because the return * this, is actually a, reference both alias, equivalent to a=5CodePudding user response:
Getobj1 returns the reference, because the return * this, is actually a, reference both alias, equivalent to a=5