- 1
Objects and classes
C++. I create an object (obj1) by passing to the constructor of the class (class1) 3 values, these values get stored in the private section of the class. Then I create a second object (obj2) by passing other 3 values to the same constructor, overwriting the 3 private variables. At this point I am wondering if I could recall the values of the variables I used to create obj1 as they are linked to the existence of the object itself, or if those values were only stored in the private section of the class and thus are gone as I overwrote them to create obj2.
4 Respostas
0
See if this helps-
https://code.sololearn.com/cAdWrL1z58pA/?ref=app
0
Avinesh Well it definitively does, thanks a lot! It makes much more sense now.
i also want to compliment the fact that you actually took the time to create a code to test my doubt.
<3
0
Francesco Derme you're welcome👍
0
Avinesh But wait this ioens another question: if as you showed me variables are linked to the existence of the object itslef and thus not stored in the class, which is the purpose of putting those variable in the class in the first place?