"johny smith" <pr**************@charter.net> skrev i en meddelelse
news:10*************@corp.supernews.com...
If I have a simple class with say a couple of integers only is there any
need for me to provide a destructor?
thanks!
No need at all. In fact, even if the class contains more complex types there
is still no need to write a constructor:
class demo
{
std::string s;
std::vector v;
....
};
demo is a complex class where the two elements shown (s and v) does have
"real" destructors - destructors that have a job to do (memory management in
this case), but there is still no need to write your own constructor - the
compiler generated destructor is just fine.
My recommendation is that you code in a way so that you normally wont have
to write any destructors at all. The only exception should be for classes
that manage some resource in one way or another. This way, the default
generated copy constructor and assignment operator will also be okay and one
less source of error has been removed.
Kind regards
Peter