2012-08-10 49 views
5

我想使用boost :: python將Python類移植到C++,希望加快Python應用程序的執行速度(我將移植到C++的類是負責約30%的應用程序執行時間)。當使用boost時獲取對自己的引用:: python

原來的Python類的初始化是這樣的:

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

如何複製這一在C++的構造函數?

如果我有一個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

您可以通過boost::python::ptr(this)使用this指針,如this answer描述。

相關問題