gpt4 book ai didi

c++ - 错误 : pure virtual method called - terminate called without an active exception - Aborted

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:10:19 30 4
gpt4 key购买 nike

在我的 A.h 文件中:

class A{
private:
unsigned short PC;
public:
A():PC(0){}
virtual ~A(){}
virtual void execute(unsigned short PC)=0;
};

在我的 B.h 文件中:

class B:public A{
private:
int status;bool exe;
public:
B:status(0),exe(false){}
virtual B(){}
void execute (unsigned short PC);
};

在我的 B.cpp 文件中:

#include <iostream>
#include "B.h"

void B::execute (unsigned short PC){
cout << "Run";
}

在我的 Functions.h 文件中:

#include "A.h"

class Functions{
public:
int status;
Functions():status(1){} // this is a constructer
void run(A *a);
};

在我的 Functions.cpp 文件中:

#include "Functions.h"
#include "A.h"
#include "B.h"

using namespace std;
void Functions::run (A *a){
a->execute();
}

在我的 Main.cpp 文件中:

#include "A.h" 
#include "B.h"

int main(int args, char**argv){
A *a;
B b;
a = &b;
Functions f;
f.run(a);
return 1;
}

当我运行时,它有一些错误:调用的纯虚方法 - 终止调用而没有事件异常 - 已中止任何人都可以我误会了吗?谢谢

最佳答案

通常在从构造函数或析构函数调用虚函数时会出现此错误。检查情况是否如此。

(我假设您的演示代码不完整)。

关于c++ - 错误 : pure virtual method called - terminate called without an active exception - Aborted,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5407304/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com