Linked Questions

268 questions linked to/from When to use virtual destructors?
47 votes
6 answers
26k views

Possible Duplicate: When to use virtual destructors? When should your C++ object's destructor be virtual?
4 votes
4 answers
9k views

Possible Duplicate: When to use virtual destructors? Virtual destructor and undefined behavior i am new to c++ and programming,i have observed that destructor is always declared virtual. may i ...
ken's user avatar
  • 836
4 votes
4 answers
6k views

Possible Duplicate: When to use virtual destructors? If all the data members of a class (which has virtual function) and it's inherited class are of non pointer type (means it can not hold any ...
user966379's user avatar
  • 3,043
5 votes
7 answers
4k views

Based on what I found here and on other links on stackoverflow, we should always define a virtual destructor in the base class if we plan to use it polymorphically. I want to know if there is an ...
3 votes
3 answers
756 views

I am playing with the code struct A { char a[20000]; A() { a[0] = 'A'; } ~A() {} }; struct B : A { char a[20000]; B() { a[0] = 'B'; } ~B() {} }; int main() { A *pA = new A;...
1 vote
2 answers
2k views

Possible Duplicate: When to use virtual destructors? [Second dicuss] hi,guys! You are all talking about virtual-destructor. And also i think about the base class`s destructor. But another test as ...
2 votes
2 answers
908 views

I'm playing around with a class hierarchy for file descriptors, where the base class holds an int and calls close on it during destruction and child classes don't add any virtual methods or data ...
1 vote
5 answers
1k views

i have been thinking, why only base class with virtual method needs virtual desctructor? look at this piece of code (read the comment): class Base{ private: int x; public: Base():x(0){} ~...
rooster's user avatar
  • 665
-3 votes
2 answers
637 views

Why do we need a virtual destructor with dynamic variables when we have inheritance? and what is the order for destructor execution in both the static/dynamic case? won't the destructor of the most ...
0 votes
2 answers
3k views

Maybe there is the same question but I haven't found it. I have following code: class MBase { public: ~MBase() { cout << "Base destructor\n" << endl; } }; class MF: public ...
1 vote
1 answer
916 views

Possible Duplicate: When to use virtual destructors? let's say i have an abstract class Animal class Animal { public: Animal(const std::string &name) : _name(name) { } virtual ...
Asher Saban's user avatar
  • 4,853
3 votes
2 answers
413 views

I'm trying to figure out the tricks of class inheritance in C++ and I've built a sample project: #include "stdafx.h" #include <iostream> using namespace std; class A { public: A() { ...
Max Mor's user avatar
  • 96
-1 votes
2 answers
162 views

In the following code, I traced by using debugger I fail to understand 1. why B b2() is never called but skipped. 2. Why auto_ptr calls base (A) destructor only when object created is derived (B)? ...
sheikhazad's user avatar
5 votes
1 answer
127 views

I am hours trying to figurate out where is the problem, but it seems so strange. I rewrote my problem in an easier way to understand. When it gets to the line where it says delete, the debbug makes ...
Isaac Michaan's user avatar
1 vote
1 answer
109 views

My question is the following : is this following code correct : class A {}; // no virtual destructor class B : public A{ std::unique_ptr<int> ptr{new int(5)}; }; // in main std::...
Antoine Morrier's user avatar

15 30 50 per page
1
2 3 4 5
...
18