当前位置: 动力学知识库 > 问答 > 编程问答 >

C++. Calling a virtual member function in destructor

问题描述:

This question already has an answer here:

  • Calling virtual function from destructor

    4 answers

网友答案:

When instantiating an object the base class gets initialized and then the subclass gets initialized. When destructing an object the subclass gets destructed and then the base class. After the subclass is destructed, its members and virtual methods are unavailable—there is no destroy() method to be invoked. I suggest you move the logic in the destroy() method to the subclass destructor.

分享给朋友:
您可能感兴趣的文章:
随机阅读: