2011-04-10 1 views
0

boost::python::objectからベースクラスへの参照を抽出できると言われました。ベースクラスの抽出ポインタ

簡単なコードは次のようになります。

// c++: 
class Base {}; 

// Export Base into python module 

// python: 
class Der(Base): 
    pass 

//c++: 
boost::python::object obj; // It points to some Der class object made from python 
boost::shared_ptr<Object> temp = extract< boost::shared_ptr<Object> >(obj); 

最後の行はで失敗します。

TypeError: No registered converter was able to produce a C++ rvalue of type boost::shared_ptr from this Python object of type Der

Baseクラスのポインタを抽出することが可能ですか?

答えて

2

したがって、this threadを使用して私の質問を管理しました。

bp::class_<Base, boost::noncopyable>("Base", bp::no_init) 

私はbp::no_initを削除する必要がありました:まず第一に、私のBaseクラスのpythonには、この方法を輸出しました。どうして?次の更新(私は前に与えたstackoverflowの記事で答え)を見てください:

class Der(Base): 
    def __init__(self): 
     super(Der, self).__init__() # Add this! 

それだそれ(:

関連する問題