This is a discussion on Explain the need for "Virtual Destructor". within the C and C++ Programming forums, part of the Software Development category; Explain the need for "Virtual Destructor" ?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| these are the following reasons to use virtual destructors:- 1. Without a virtual destructor, the proper destructor may not be called: struct B {~B();}; struct D : B {~D();}; B* b = new D; delete b; // <--------- Will not call D::~D() !!!!! 2. Without a virtual destructor, operator delete(void*, size_t) may not be called with the correct size. struct B {~B(); operator delete(void*, size_t);}; struct D : B {~D();}; B* b = new D; delete b; // <--------- Will call operator delete(void*, size_t) with // the size of B not the size of D!!! 3. Without a virtual destructor, and when MI is used, operator delete(void*) or operator delete (void*, size_t) may be called with the wrong address. struct B {~B();}; struct A {}; struct D : A, B {~D();}; B* b = new D; delete b; // <--------- May not pass to operator delete the address // that was returned by operator new!!! |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Anybody explain about "Common Type System" (CTS)? | H2o | ASP and ASP.NET Programming | 5 | 08-09-2007 08:02 AM |
| Explain "passing by value", "passing by pointer" and "passing by reference" | Sabari | C and C++ Programming | 1 | 07-30-2007 11:29 PM |
| I keep getting "Data Missing" when I click the "back" button in my browser. How can I | oxygen | HTML, CSS and Javascript Coding Techniques | 1 | 07-28-2007 01:12 AM |
| Why do I get "HTTP 500" error(or "(DLL)initialization routine failed")in my browser? | kingmaker | ASP and ASP.NET Programming | 1 | 07-20-2007 04:38 AM |
| Explain the need for virtual destructor | prasath | C and C++ Programming | 1 | 07-17-2007 06:01 AM |