2012-06-13 35 views
1

是否有某些類不能被boost :: python包裝?我試圖包裝一個類,但是在使用它的時候會碰到錯誤,而不是虛擬類。不能通過boost包裝的類:: python

下不工作...

#include <manu/manu.h> 

void foo() 
{ 
    // can call non-member Kernel(), which returns Kernel instance 
    manu::Kernel* kernel = manu::Kernel(); 
} 

BOOST_PYTHON_MODULE(mymodule) 
{ 
    using namespace boost::python; 
    class_<manu::Kernel>("Kernel", no_init) // doesn't like this 
    ; 
} 

我可以在一個函數中使用它,而是把它在class_模板,我得到了以下錯誤:

manu_python.cpp:9: error: expected constructor, destructor, or type conversion before ‘*’ token 
manu_python.cpp: In function ‘void init_module_manu()’: 
manu_python.cpp:17: error: type/value mismatch at argument 1 in template parameter list for ‘template<class T, class X1, class X2, class X3> class boost::python::class_’ 
manu_python.cpp:17: error: expected a type, got ‘manu::Kernel’ 

但使用一個虛擬班級確實有效。

class Foo 
{ 
}; 

BOOST_PYTHON_MODULE(mymodule) 
{ 
    using namespace boost::python; 
    class_<Foo>("Kernel", no_init) 
    ; 
} 

完整的類在manu.h中定義,但沒有在那裏完全聲明。這個類是不是暴露給python?

在manu.h中,有一個名爲Kernel的類和一個名爲Kernel()的非成員函數,它返回一個Kernel實例。這個函數是否影響了Kernel類在模板中的使用?如果是這樣,有沒有辦法告訴我指的是類而不是函數聲明的模板?

+0

在你的榜樣,您呼叫馬努::內核()並返回指向manu :: Kernel的指針。什麼manu :: Kernel是? – LavaScornedOven

+0

對不起。這是一個函數,它返回內核的一個實例。該函數恰好與該類具有相同的名稱。這有問題嗎? – voodoogiant

+1

我不是專家,但我的猜測是編譯器解決了class_ 中的manu :: Kernel作爲函數類型,而不是作爲類。嘗試將manu :: Kernel函數的名稱更改爲其他內容(可能是CreateKernel或其他)。 – LavaScornedOven

回答