4
請看下面的例子:轉換升壓:: shared_ptr的中的boost :: python的函數調用
#include "Python.h"
#include <boost/python.hpp>
#include <boost/shared_ptr.hpp>
class A {};
class B : public A{};
void foo(boost::shared_ptr<A>& aptr) { }
BOOST_PYTHON_MODULE(mypy)
{
using namespace boost::python;
class_<A, boost::shared_ptr<A> >("A", init<>());
class_<B, boost::shared_ptr<B>, bases<A> >("B", init<>());
def("foo", foo);
}
,如果我叫Python代碼
import mypy
b = mypy.B()
mypy.foo(b)
我得到
ArgumentError: Python argument types in
mypy.foo(B)
did not match C++ signature:
foo(boost::shared_ptr<A> {lvalue})
我搜索了很多,但我找不到一個很好的解釋/修復/解決方法。任何幫助都非常歡迎!
如果你有'foo'採取'boost :: python :: object'參數,然後從中提取'shared_ptr',會發生什麼? – Useless
當然,這是可行的,但我希望沒有爲foo編寫任何額外的包裝會有一種方法(我會需要相當多的包裝) – Hans