I'm totally stalled, after battling this bug for hours after hours my worst fears came true. In the sample code below, where B inherits from A but is still pointed at by an A* pointer the B destructor IS NOT called (even if they use virtual methods). Now a solution/workaround to this is not hard to make, but is this really intended (standard) behavour or is my compiler just plain insane? I can't believe I've never discovered this earlier...
Code:#include <iostream> class A { public: A() { std::cout << "A::A()" << std::endl; } ~A() { std::cout << "A::~A()" << std::endl; } protected: }; class B : public A { public: B() { std::cout << "B::B()" << std::endl; } ~B() { std::cout << "B::~B()" << std::endl; } protected: }; int main() { A* b = new B(); delete b; return 0; }



LinkBack URL
About LinkBacks


