UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » C++
  • » Question about virtual destructor

#1 2009-07-31 09:47 AM

tomcio
Member
From: Poland
Registered: 2006-08-14
Posts: 113

Re: Question about virtual destructor

Hello!

Me class derives from class, which doesn't provide virtual destructor. I declared virtual destructor in my class. Would object destruction work the same as in class derive from class with virtual destruction?

Offline

#2 2009-08-04 02:15 PM

yurec
Member
From: Singapore
Registered: 2006-11-16
Posts: 134

Re: Question about virtual destructor

Hi,

When you add virtual destructor it works as other virtual methods. So if you use a pointer to a base class object, which refers to derived class object and call delete on this object you will get ~Derived() and then ~Base(). And that is a correct behavior. If you don't have a virtual destructor in Base class you will not be able to destruct an object of Derived class through the pointer to Base.

Yurij

Offline

  • Index
  • » C++
  • » Question about virtual destructor

Board footer

Powered by FluxBB