c++ - 类不能被 boost::python 包装

标签 c++ templates boost 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的实例。此函数是否会影响内核类在模板中的使用?如果是这样,有没有办法告诉模板我指的是类而不是函数声明?

最佳答案

我遇到了同样的问题并找到了这个网站: http://qiita.com/nishio/items/daff0e9be30f4b4d6fca

少数可读位为我解决了这个问题:

#include <boost/python/class.hpp>

关于c++ - 类不能被 boost::python 包装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11022873/

相关文章:

c++ - std::sort 函数的编译器错误 (GCC 4.4)

c++ - 如何将结构模板标记为好友?

php - JS 中的模板?

C++/Boost 共享资源类,用于管理资源生命周期,如 shared_ptr

c++ - 展平一系列序列(序列)

c++ - 无法访问公共(public)静态变量成员

c++ - 为 std::complex 重载标准运算符<<

c++ - 如何检查和处理非常接近于零的数字

javascript - WordPress仅在用户未登录时执行javascript文件

c++ - 未找到共享对象但存在于链接器目录中