调用C++ virtual方法导致析构函数被调用

我的程序中定义了一个抽象类(比如叫AdvectionManagerInterface),子类AdvectionManager继承AdvectionManagerInterface。当我调用AdvectionManager的一个virtual方法density时,结果AdvectionManager的析构函数被调用,如下图所示

图片描述

请问该如何理解呢?我的程序稍微有些复杂,不方便隔离出问题代码,请大家支支招!十分感谢!

编辑:density函数的内容是:

    virtual double
    density(const TimeLevelIndex<2> &timeIdx, int tracerIdx, int cellIdx) const {
        return meshAdaptor.mass(timeIdx, tracerIdx, cellIdx)/meshAdaptor.volume(cellIdx);
    }

不知道能看出什么端倪~

再编辑:output函数在main函数中调用:

#include "lasm.h"

using namespace lasm;

int main(int argc, char const *argv[])
{
    if (argc != 2) {
        REPORT_ERROR("Configure file path is needed!");
    }
    ConfigManager configManager;
    Cartesian3DTest test;
    AdvectionManager advectionManager;
    TimeLevelIndex<2> oldIdx;

    configManager.parse(argv[1]);

    test.init(configManager, advectionManager);
    test.setInitialCondition(advectionManager);
    test.output(oldIdx, advectionManager);
    return 0;
}
阅读 2.7k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题