<> Do it today c++ Problems encountered

<> How to use the same member function in a class You can output a value It can also be used as a modifiable left value :

here 24 Line is wrong , The error is displayed as a.getValue() Not a modifiable left value .

For a long time ,
I found it could be changed like this :

So why can we change that ?

Because at this time A pass the civil examinations 9 We have << Operator overload is output A Members of num, here a.getValue() Return to a A Object reference for , Then main23 Line can be output successfully .

Note that No 11 Member function in row A& getValue() Back to A References to , If it is A getValue() Then only A type
, Then main In a.getValue() Will call the copy constructor to create a a Exactly the same object a‘, Then the k Assign to a’ Members of a’.num,a.num unchanged .

The code is as follows , I don't know how to try it on my own compiler , understand :
class A { public: int num; A(int t) { num = t; } A(const A& p) { num = p.num; }
friend ostream& operator <<(ostream& out,const A p) { out << p.num; return out;
} int getValue() { return this->num; } A& getValue(){ return this->num; } }; int
main() { int m=3, k=10; A a(m); cout << a.getValue() << endl; a.getValue() = k;
cout<<a<<endl; return 0; }

©2019-2020 Toolsou All rights reserved,
Golang Array bisection , Array split , Array grouping Map---Java judge Map Contains a key Online troubleshooting HTTP Status code ——415 and 406ElementUI In the select Of label value ( Essence )2020 year 6 month 26 day C# Class library GUID Help class [RK3399][Android7.1] Learning notes DRM Driver development ( introduce ) about Navicat for mysql Of 2003 error airflow Timed tasks + Time setting +cron expression Vue Transfer parameters and receiving of page Jump SpringBoot JpaRepository Database addition, deletion, modification and query