Boost python:Wrapped和Base类之间的参数错误左值

时间:2016-11-08 13:33:32

标签: python c++ boost-python

在下面的Python代码中,findFactory会返回FactoryBase而非FactoryBaseWrapper
我认为这可能是问题的原因 你知道如何告诉python FactoryBaseWrapper从FactoryBase继承吗? 我试过" base"在课堂上像这样:

class_<FactoryBaseWrapper, bases<FactoryBase> boost::noncopyable>( "FactoryBase", no_init )

但它没有编译。好像我需要从FactoryBase创建界面。但我不能,因为Factorybase中的纯虚函数,我需要FactoryBaseWrapper。

由于

Python代码:

_sourceFactory = _myFactoryMgr.findFactory(name)
foo = _sourceFactory.getOrCreateBase(myObj) # Problem Here

BoostPython模块:

class_<FactoryMgr, boost::noncopyable>("FactoryMgr",no_init)
  .def("findFactory",&FactoryMgr::findFactory, return_value_policy<reference_existing_object>());

class_<FactoryBaseWrapper, boost::noncopyable>( "FactoryBase", no_init )
.def( "getOrCreateIndicator", &FactoryBaseWrapper::getOrCreateIndicator, return_value_policy<reference_existing_object>())

Cpp功能&amp;课程:

        class FactoryMgr
        {    
          FactoryBase* FactoryMgr::findFactory( const std::string& name );
        }
        class FactoryBaseWrapper :public FactoryBase, public wrapper<FactoryBase>
        {
           Base* FactoryBase::getOrCreateBase ( const CustomObject* myObj);
           Base* createBase( string str )
           {
             return this->get_override( "createBase" )();
           }
        } 
        class FactoryBase
        {
           virtual Base* createBase( string str )=0;
           ...
        }

我收到此错误:

Traceback (most recent call last):
  File "XXX", line 149, in YYYY
_sourceFactory.getOrCreateBase(myObj)
Boost.Python.ArgumentError: Python argument types in
    FactoryBase.getOrCreateBase(FactoryBase, CustomObject)
did not match C++ signature:
    getOrCreateBase(FactoryBaseWrapper {lvalue}, Interface::CustomObject const*)

0 个答案:

没有答案