2012-08-10 1 views
5

私はPythonクラスをC++に移植しようとしています。これは、Pythonアプリケーションの実行速度を上げるためにboost :: pythonを使用しています(C++に移植するクラスはアプリケーションの実行時間の約30%を占める)。私はC++のコンストラクタでこれを複製するにはどうすればよいboost :: pythonを使用しているときに自己参照を取得する

class PyClass(object): 
    def __init__(self, child): 
     child.set_parent(self) 
     ... 

オリジナルのPythonクラスのinitはのように見えますか?

私はC++クラスを持っている場合:

class CClass 
{ 
    // to get input args that match the Python class I need 
    CClass(boost::python::object &child) 
    { 
     // but how do I get the boost::python::object self 
     // as I only have *this in C++ ? 
     CClass& c = boost::python::extract<CClass&>(child); 
     c.set_parent(self); 
    } 

    ... 
} 

おかげで、マーク

答えて

3

this answerで説明したようにあなたは、boost::python::ptr(this)経由thisポインタを使用することができます。

関連する問題