>  Q&A  >  본문

inheritance - 调用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;
}
伊谢尔伦伊谢尔伦2713일 전523

모든 응답(0)나는 대답할 것이다

답장 없음
  • 취소회신하다