Is there anyway to use boost python wrappers in headers?
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::Get开发者_开发技巧Priority)
.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
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:
inline void DeclareStatusEffect()
{
boost::python::class_<StatusEffect>("StatusEffect")
.def("GetPriority", &StatusEffect::GetPriority)
.def("GetDescription", &StatusEffect::GetDescription)
.def("GetName", &StatusEffect::GetName);
}
And this into your source file:
BOOST_PYTHON_MODULE(Status_Effect)
{
DeclareStatusEffect();
}
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.
精彩评论