纯虚函数调用 [英] Pure virtual function call
本文介绍了纯虚函数调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用boost.python来编写python模块c ++。我有一些基本类与纯虚拟函数,我已导出像这样:
I'm using boost.python to make python-modules written in c++. I have some base class with pure virtual functions which I have exported like this:
class Base
{
virtual int getPosition() = 0;
};
boost::python::class_<Base>("Base")
.def("GetPosition", boost::python::pure_virtual(&Base::getPosition));
在Python中我有代码:
in Python I have code:
class Test(Base):
def GetPosition(self):
return 404
Test obj
obj.GetPosition()
RuntimeError:纯虚函数
RuntimeError: Pure virtual function called
出现什么问题?
推荐答案
一个析构函数直接或间接调用一个纯虚拟成员。
This error happens when a constructor or a destructor directly or indirectly calls a pure virtual member.
(请记住,在构造函数和析构函数执行期间,动态类型是构造/对于该类型)。
(Remember that during constructor and destructor execution, the dynamic type is the constructed/destructed type and so virtual members are resolved for that type).
这篇关于纯虚函数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文