LinuxGuy wrote:
I just want to know .. In a normal class if I declare destructor as
virtual then what are the implecation to class/ processing / time.
It means, on a typical implementation, one more entry in the vtable for
that class (trivial, a minimal one-time cost per class), and an
additional pointer dereference (for vtable lookup) when the destructor
is invoked.
So, very minimal. Worth doing if there's any chance at all that
someone will eventually use it as a base class, because the resources
you'll leak if that happens and they forget to virtualize the
destructor will be a much bigger problem than the trivial additional
overhead I just described. Unless you're programming for an embedded
system or something, it may be a good idea to provide a virtual dtor
for every class rather than risk this. That, or make it impossible to
derive from your class. How to do that is left as an exercise for the
interested coder.
I assume you already know that if it's a base class (or has any virtual
member functions, which implies that it's intended to be a base class)
you should always provide a virtual dtor.
Luke