C++: is it right to delete all declarations in public and private? -
i learning c++ , not clear destructor of class. example:
class a: { public: int valuea; private: int valueb; }; a:~a() { delete valuea; delete valueb; }
so, right delete every declarations in public , private?
no, need delete
has been allocated using new
. simple value types int
s never need deleted.
if class did include data dynamically allocated using new
either constructor or later other method destructor should typically de-allocate of it, regardless of wether data public or private.
i might add having publically visible dynamically allocated pointer members might not best design, though.
Comments
Post a Comment