C
Charles Keepax
Sorry about the newbie question. If a class contains a pointer to some
data, and memory is allocated to that pointer in the constructor.
Naturally the destructor should free that memory, right? So since C++ is
by default call-by-value, if you pass that class as an arguement to a
function a copy of the class will be made however a copy of the data
isn't. Thus when the function reaches its end, the class destructor will
be called thus destroying the data. However the original object still
exists and when it trys to reference the data an error will result. So
finally, my question is appart from passing the class as a reference
arguement or pointer is there anything that can be done to prevent this?
Thanks,
Charles
data, and memory is allocated to that pointer in the constructor.
Naturally the destructor should free that memory, right? So since C++ is
by default call-by-value, if you pass that class as an arguement to a
function a copy of the class will be made however a copy of the data
isn't. Thus when the function reaches its end, the class destructor will
be called thus destroying the data. However the original object still
exists and when it trys to reference the data an error will result. So
finally, my question is appart from passing the class as a reference
arguement or pointer is there anything that can be done to prevent this?
Thanks,
Charles