+ 1

[Abandoned] the value doesn't get updated when outputting it through another function

This is a MRE(Minimum Reproducible Example) as the original code is too big to fit. I want to output the updated value in id_assign function, but it seems that it doesn't update the value which was updated in id_assign function and then printing out the same variable in another function in different class. I did find some workarounds involving implementing that function with arguements in the main function, which I don't want it. thanks to Ipang for feedback https://code.sololearn.com/c2fg0ImLc3uq

20th Dec 2021, 5:27 AM
Rellot's screwdriver
Rellot's screwdriver - avatar
2 Respostas
+ 4
Rellot's screwdriver I think I don't get what you're trying to do. You didn't pass any parameters for your object, and you didn't call the function which assigns default values to them. Then why do you expect your variable to have anything other than the default initialized(0) value?
20th Dec 2021, 7:05 AM
Rishi
Rishi - avatar
+ 3
Hm, I saw your previous question on this, too 🤔 Back then, Ipang said that in your code assign_id was never called and thus value_one was never updated. 🤔 Here, it is the same problem. The constructor calls 'output'. Neither assign_id nor assign_arguements is ever called. So, I wonder again why you expect the output to be 4. If you call to assign a value to value_one, then the output becomes 4: auto d = Display(); d.assign_arguements(); d.output(); There must be something about your problem that I don't understand 🤔🙂
20th Dec 2021, 6:10 AM
Agnes Ahlberg
Agnes Ahlberg - avatar