c++,exception,virtual-destructor
OK, someone already answered your first question. I'll focus on this one: if the exception destructor should be called when go out of catch scope, in this case only the base class A's d'tor will be called? The implementation will always destroy the exception object properly regardless of how it...
I guess your compiler optimizes the code and removes the useless part, including 10/i in the base class destructor. Try with this: #include <iostream> using namespace std; static int i=1; class Parent { public: virtual ~Parent(){int tmp = 10/i; cout << tmp; } }; class Child: public Parent { public:...
c++,casting,virtual-destructor
For the case you mentioned above you just got lucky that the address of B's destructor is the same of A's destructor in terms of offset from the pointer. The virtual destructor is just another entry in the vftable of the object. You can call any destructor (no matter how...
c++,destructor,virtual-destructor
in addition to R Sahu answer, note that std::queue<> destructor is not virtual, any deletion from a pointer to Base will invoke undefined behavior (for that reason, you should generally not inherit from standard containers). You should probably review your design, such as using a class member instead of inheritance,...
c++,visual-c++,gcc,warnings,virtual-destructor
The class in question has no destructor (virtual or otherwise). Fun fact: All objects in C++ have a destructor. It's simply that if you don't define one, the compiler generates it, and for primitives, it's a no-op. Why is the compiler generated destructor not virtual? Because people complained that...
The problem is virtual ~ISolution() = 0; the destructor is not implemented. Try virtual ~ISolution() { } instead. This is needed even when only instances of the derived class are created, because destructors are special. In a normal function, the base class implementation needs to be called explicitly, like void...
c++,polymorphism,destructor,virtual-destructor
No, virtual destructor declaration/definition of the Base class is sufficient, though making it abstract requires you give this destructor in the Derived class. If you just declare class Base { public: virtual ~Base() {} // <<< Have a definition }; you don't need to specify any destructors in inherited classes....
c#,inheritance,syntax,virtual-destructor
C# doesn't have deterministic destruction. In fact, it doesn't really have destructors, per se: it has finalizers and IDisposable. The GC will clean things up if and when it gets around to garbage collecting the object instance. All objects will [eventually] get cleaned up one way or another when the...
c++,c++11,memory-management,polymorphism,virtual-destructor
The line reinterpret_cast<Base*>(ptr)->Base::~Base(); simply needs to be reinterpret_cast<Base*>(ptr)->~Base(); instead....