在我的Ah文件中:
class A{
private:
unsigned short PC;
public:
A():PC(0){}
virtual ~A(){}
virtual void execute(unsigned short PC)=0;
};
Run Code Online (Sandbox Code Playgroud)
在我的Bh文件中:
class B:public A{
private:
int status;bool exe;
public:
B:status(0),exe(false){}
virtual B(){}
void execute (unsigned short PC);
};
Run Code Online (Sandbox Code Playgroud)
在我的B.cpp文件中:
#include <iostream>
#include "B.h"
void B::execute (unsigned short PC){
cout << "Run";
}
Run Code Online (Sandbox Code Playgroud)
在我的Functions.h文件中:
#include "A.h"
class Functions{
public:
int status;
Functions():status(1){} // this is a constructer
void run(A *a);
};
Run Code Online (Sandbox Code Playgroud)
在我的Functions.cpp文件中:
#include "Functions.h"
#include "A.h"
#include "B.h"
using namespace std;
void Functions::run (A *a){
a->execute();
}
Run Code Online (Sandbox Code Playgroud)
在我的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;
}
Run Code Online (Sandbox Code Playgroud)
当我运行时,它有一些错误:"调用纯虚方法 - 终止调用而没有活动异常 - 中止"任何人都可以在哪里误解?谢谢
Ale*_*tov 15
通常,在从构造函数或析构函数调用虚函数时会出现此错误.检查是不是这种情况.
(我假设你的演示代码不完整).