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

24th Dec 2019, 5:16 PM
Francesco Derme
Francesco Derme - avatar
4 Respuestas
24th Dec 2019, 6:33 PM
Avinesh
Avinesh - avatar
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
24th Dec 2019, 7:02 PM
Francesco Derme
Francesco Derme - avatar
0
Francesco Derme you're welcome👍
25th Dec 2019, 1:07 AM
Avinesh
Avinesh - avatar
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?
25th Dec 2019, 3:46 PM
Francesco Derme
Francesco Derme - avatar