2012-06-13 34 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

回答