开发者

Is there a difference between calling a member function from a leaf class in or out of the destructor body?

I have a specific case which is hard to isolate in a code snippet here but I can explain it...

I have a class A : public B and A has a member pointer of some type foo * f. In the virtual destructor for A, I have something like:

A::~A() { shutdown(); }

where, shutdown is nonvirtual and looks something like: void A::shutdown() {delete f;}

it turns out at runtime this gives me a "pure virtual method called terminate called without an active exception Aborted (core dumped)" but if I remove shutdown() from the body of the destructor and call it directly, and then let the destructor run...I no longer get this...

What could possibly be causing beh开发者_C百科avior of this sort? I've tried stepping with gdb but it's huge and I'm not even sure what to look for. Any ideas would be very much appreciated!


Either shutdown is a pure virtual function somewhere up the inheritance tree, or it calls another member function which is pure virtual somewhere up the inheritance tree. Either directly or indirectly, but that's what happens.

Check the execution path to see where the call is made and get rid of it.


If A has both the shutdown method AND the pointer f, don't call shutdown() at all. Just delete f in the destructor directly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜