<> 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 :

Above A::getValue() To return a int,
In the figure below getvalue() Obviously not modifiable lvalue :

Because we need to realize the above 23,24 That's ok ,
For a long time ,
I found it could be changed like this :
Add overload function << And put the getValue() The return type of is changed to A&:

Combined, a member function in a class can be used as a modifiable left value and directly << output

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,
keras from dataframe Read data and enhance the data for training ( classification + division )( Essence )2020 year 6 month 26 day C# Class library read json Profile help class airflow Timed tasks + Time setting +cron expression Redis Counter High concurrency applications el-ui:select Get value ( Essence )2020 year 8 month 15 day redis database StackExchange.Redis in Set type (C# edition )( Essence )2020 year 6 month 26 day C# Class library model PageInputpython read , write in txt Text content PHP Printout log Note 14 : The second biggest obstacle to motivating others in R & D management