无论如何,有没有在标头中使用 boost python 包装器?
是否有在头文件中使用 BOOST_PYTHON_MODULE ?例如,我希望能够
BOOST_PYTHON_MODULE(Status_Effect)
{
boost::python::class_<StatusEffect>("StatusEffect")
.def("GetPriority", &StatusEffect::GetPriority)
.def("GetDescription", &StatusEffect::GetDescription)
.def("GetName", &StatusEffect::GetName);
}
在头文件中声明此模块。然而,每当我尝试时,它都会抱怨多个定义。有谁知道在头文件中进行包装的方法吗?
谢谢
Is there anyway to use BOOST_PYTHON_MODULE in a header file? For instance, I'd like to be able to declare this Module
BOOST_PYTHON_MODULE(Status_Effect)
{
boost::python::class_<StatusEffect>("StatusEffect")
.def("GetPriority", &StatusEffect::GetPriority)
.def("GetDescription", &StatusEffect::GetDescription)
.def("GetName", &StatusEffect::GetName);
}
in a header file. Whenever I try however, it complains about multiple definitions. Does anyone know of a way to do the wrapping in a header file?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方法如下:括号内的内容只是普通的 C++ 代码。所以你可以将该部分移动到内联函数中。
例如,您可以将其放入标头中:
将其放入源文件中:
您还可以查看
BOOST_PYTHON_MODULE
宏的作用,也许有一种方法可以将更多内容放入标头中,但是对于未来版本的 Boost.Python 来说,这可能不安全,即使你让它可以工作。Here's a workaround: What's inside of the parentheses is just ordinary C++ code. So you could move that part into an inline function.
For example, you could put this into the header:
And this into your source file:
You can also look at what the
BOOST_PYTHON_MODULE
macro does, and maybe there's a way to put even more into the header, but that's probably not safe to do with future versions of Boost.Python, even if you get it to work.