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

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -