hi,
Could anyone explain me about this warning? (and how take out it) thanks
Qt Code:
warning 'class Cri' has virtual functions but non-virtual destructorTo copy to clipboard, switch view to plain text mode
hi,
Could anyone explain me about this warning? (and how take out it) thanks
Qt Code:
warning 'class Cri' has virtual functions but non-virtual destructorTo copy to clipboard, switch view to plain text mode
Regards
Actually it should be explained in any book that covers C++ basics.Originally Posted by mickey
Qt Code:
class A { public: A() {} virtual foo() {} ~A() {} }; class B : public A { public: B() {} virtual foo() {} ~B() {} }; ... A *ptr = new B(); ptr->foo(); // B::foo() will be called, since ptr is in fact B instance, not A delete ptr; // only A::~A() will be called, because destructor isn't virtual, hence the object won't be destructed properly.To copy to clipboard, switch view to plain text mode
Just read the error message and it will tell you what you need.Originally Posted by mickey
But it IS annoying that you still get the warning if you don't have a destructor at all. I often have to add an empty virtual destructor to avoid it.
"The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry
Then you have a default one, which isn't virtual.Originally Posted by Michiel
Oh, never mind. I was arguing that the default destructor is empty, so doesn't have to be called. But the problem is, of course, that the destructor of the subclass needs to be called. If you don't make the superclass one virtual, that one gets called instead, empty or not.
Still annoying, though. I'd be ok with making it default behaviour in the case of other virtual members.
Last edited by Michiel; 13th August 2006 at 10:24. Reason: My mistake
"The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry
Bookmarks