1 - const intlong & amp; Operator=(const intlong&)
2 - intlong & amp; Operator=(const intlong&)
I thought the first return value cannot be modified with const said, only as a constant returns, but tests found and the second is the same, can be used for continuous assignment
For example,
Intlong a (5);
Intlong b (0);
Intlong c (6);
A=b=c;
- the return value is 1 const and 2 kinds of return value without a const what's the difference?
There are
3 - intlong & amp; Operator=(const intlong&) Const;
4 - intlong operator=(const intlong&) Const;
The two defined as const overloaded assignment operator have what effect?
- do not modify this internal members how to change the value of this assignment? . Does that mean overloaded assignment operator in addition to meaningful 1 and 2, 3 and 4 meaningless
#include
using namespace std;
The class intlong {
Friend ostream & amp; Operator<(ostream& , const intlong&);
Public:
Intlong (int);
Intlong (const intlong&);
Intlong operator + (const intlong&) Const;
Const intlong & amp; Operator=(const intlong&);//adding const
//intlong & amp; Operator=(const intlong&);//the front without const cons and how cannot define a const class
Private:
Int p;
};
Const intlong & amp; Intlong: : operator=(const intlong& RHS) {
This - & gt; P=RHS. P;
Return * this;
}
/*
Intlong & amp; Intlong: : operator=(const intlong& RHS) {
This - & gt; P=RHS. P;
Return * this;
} */
Ostream & amp; Operator<(ostream & amp; Cout, const intlong & amp; RHS) {
Cout
}
Intlong: : intlong (int RHS) : p (RHS) {
}
Intlong: : intlong (const intlong & amp; RHS) {
This - & gt; P=RHS. P;
}
Intlong intlong: : operator + (const intlong & amp; RHS) const {
Intlong temp (0);
Temp. P=(* this). P + RHS. P;
Return temp.
}
Int main ()
{
Intlong a (5);
Intlong b (6);
Intlong c (7);
A=b=c;
Coutreturn 0;
}
CodePudding user response:
The return value is the right value, const modifiers rvalue doesn't make any senseCodePudding user response:
T a=b in this case, whether b const, replication, can occur in aA simple example
int a=1; 1//here is obviously a const int because it is a literal, cannot be rewritten, execute the statement after 1 this data will be copied into a storage unit of the
CodePudding user response:
The T operator=(.. ) const is the assignment operator error, because the assignment will be to modify, and const is not allowed to change, so wrongCodePudding user response: