错误:纯虚方法调用 - 终止调用没有活动异常 - 中止 [英] Error: pure virtual method called - terminate called without an active exception - Aborted

查看:167
本文介绍了错误:纯虚方法调用 - 终止调用没有活动异常 - 中止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的A.h档案中:

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

在我的Bh文件中:

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

在我的B.cpp文件中:

In my B.cpp file:

#include <iostream>
#include "B.h" 
void B::execute (unsigned short PC){
cout << "Run";
}

在我的Functions.h文件中:

In my Functions.h file :

#include "A.h"
class unctions{
public: int status;
Functions():status(1){} // this is a constructer
void run(A *a);
};

在我的Functions.cpp文件中:

IN my Functions.cpp file:

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

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



在我的Main.cpp文件中:

In my Main.cpp file:

#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;
}

当我运行时,它有一些错误:
pure virtual方法调用 - 终止调用没有活动异常 - 中止
任何人我在哪里误会了?
谢谢

When I run , it has some error: "pure virtual method called - terminate called without an active exception - Aborted " Can anybody where did I misunderstand? Thank you

推荐答案

通常,当从构造函数或析构函数调用虚函数时,会收到此错误。
检查是否是这种情况。

Usually you get this error when call your virtual function from constructor or destructor. Check that that is not the case.

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

(I assume that your demo code is not complete).

这篇关于错误:纯虚方法调用 - 终止调用没有活动异常 - 中止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆