0
Question about challenge code
int& fun(){ int x = 10; return x; } int main(){ fun() = 30; std::cout<<fun(); return 1; } What does "fun() = 30;" do and where might such expression be used?
5 Answers
+ 1
Hi. look at this
https://code.sololearn.com/cRGNW6Nso58C/?ref=app
In many libraries and frameworks (Qt for example) you can work with incapsulated fields with 'set' and 'get' methods or with 'r' (reference) methods.
'r' methods are analogs of your code.
0
Yeah, sorry. I typed it from memory and made some dumb mistakes. I edited the original post with proper code.
- 1
I figured it out a bit, I think?
Apparently, if there is a static variable in the function, that statement changes the value of it.
I guess I'll have to test it on computer to find out all possible cases because Google is not helping me this time.