Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/163.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
std::从C+;派生的具体Python类的共享ptr+;使用boost::python抽象类 我正在处理的C++库中的重要功能依赖于代码:ST::SyrdYPPTR < /C>。例如,要向参与者添加组件,我将使用prototype调用函数 Actor::add_component(std::shared_ptr<Component> cmp);_C++_Shared Ptr_Boost Python - Fatal编程技术网

std::从C+;派生的具体Python类的共享ptr+;使用boost::python抽象类 我正在处理的C++库中的重要功能依赖于代码:ST::SyrdYPPTR < /C>。例如,要向参与者添加组件,我将使用prototype调用函数 Actor::add_component(std::shared_ptr<Component> cmp);

std::从C+;派生的具体Python类的共享ptr+;使用boost::python抽象类 我正在处理的C++库中的重要功能依赖于代码:ST::SyrdYPPTR < /C>。例如,要向参与者添加组件,我将使用prototype调用函数 Actor::add_component(std::shared_ptr<Component> cmp);,c++,shared-ptr,boost-python,C++,Shared Ptr,Boost Python,我希望创建自定义组件,如下所示: import library class Derived(library.Base): def custom_behavior(self): print "Derived::custom_behavior()" def main(): # Instance of a Python class derived from a C++ class. derived = Derived() print "dire

我希望创建自定义组件,如下所示:

import library

class Derived(library.Base):
    def custom_behavior(self):
        print "Derived::custom_behavior()"


def main():

    # Instance of a Python class derived from a C++ class.
    derived = Derived()

    print "direct call to Derived.behavior..."
    derived.behavior()

    print "call foo(const Base& item)"
    library.foo(derived)

    print "call bar(const Base* const item)"
    library.bar(derived)

    print "call baz(const std::shared_ptr<Base>& item)"
    library.baz(derived)


if __name__ == "__main__":
    main()
我试图重写从
library.Base
派生的所有Python类的构造函数,希望以
std::shared\u ptr
的形式“开始存在”:

std::shared_ptr构造函数(){
返回std::make_shared();
}
阶级_
(“基本”,无初始)
.def(“\uuuu init\uuuuu”,make\u构造函数(构造函数))
//…其他方法
;
但这并没有奏效---有什么建议吗

import library

class Derived(library.Base):
    def custom_behavior(self):
        print "Derived::custom_behavior()"


def main():

    # Instance of a Python class derived from a C++ class.
    derived = Derived()

    print "direct call to Derived.behavior..."
    derived.behavior()

    print "call foo(const Base& item)"
    library.foo(derived)

    print "call bar(const Base* const item)"
    library.bar(derived)

    print "call baz(const std::shared_ptr<Base>& item)"
    library.baz(derived)


if __name__ == "__main__":
    main()
$ python test-library.py
direct call to Derived.behavior...
Derived::custom_behavior()
call foo(const Base& item)
Derived::custom_behavior()
call bar(const Base* const item)
Derived::custom_behavior()
call baz(const std::shared_ptr<Base>& item)
Traceback (most recent call last):
  File "test-library.py", line 27, in <module>
    main()
  File "test-library.py", line 23, in main
    library.baz(derived)
Boost.Python.ArgumentError: Python argument types in
    library.baz(Derived)
did not match C++ signature:
    baz(std::shared_ptr<Base>)
std::shared_ptr<BaseWrapper> constructor() {
    return std::make_shared<BaseWrapper>();
}

class_<BaseWrapper, std::shared_ptr<BaseWrapper>, noncopyable>
    ("Base", no_init")
    .def("__init__", make_constructor(constructor))
    // ... other methods
    ;