Home > Articles > Programming > C/C++

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend

Make Your Destructors Virtual

As we saw earlier, making destructors virtual is a terrific way of ensuring that resource deallocation can occur. This is a feature of C++ that comes for free and is well worth using as a matter of course. Virtual destructors are automatically invoked, so there’s no big effort required on the programmer’s part. However, do remember that virtual functions aren’t as efficient as their nonvirtual counterparts. So, if performance is a key requirement, you might like to carefully consider the use of virtual functions.

  • + Share This
  • 🔖 Save To Your Account