Boost Python - 具有默认参数问题的重载函数
我有一个具有两个函数的类,这两个函数都采用不同的参数集,并且都有默认参数,如下所示:
void PlaySound(const std::string &soundName, int channel = 0, bool UseStoredPath = true);
void PlaySound(FMOD::Sound* sound, int channel = 0);
我从此处的教程中找到了如何执行默认参数重载
http://www.boost.org/doc/libs/1_37_0/libs/ python/doc/v2/overloads.html
以及如何在此处采用不同参数类型进行函数重载
http://boost.2283326.n4.nabble.com/ Boost-Python-def-and-member-function-overloads-td2659648.html
我最终做了这样的事情......
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(PlaySoundFromFile, Engine::PlaySound, 1, 3)
BOOST_PYTHON_MODULE(EngineModule)
{
class_<Engine>("Engine")
//Sound
.def("PlaySound", static_cast< void(Engine::*)(std::string, int, bool)>(&Engine::PlaySound));
}
问题是我真的不知道如何同时使用它们。我想避免更改我的基类函数定义。
以前做过此操作或知道如何操作的人可以帮助我吗?
提前致谢
I have a class that has two functions, both of which take a different set of parameters and both of which have default arguments like so:
void PlaySound(const std::string &soundName, int channel = 0, bool UseStoredPath = true);
void PlaySound(FMOD::Sound* sound, int channel = 0);
I've found how to do default argument overloads from the tutorial here
http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/overloads.html
as well as how to do function overloads taking different parameter types here
http://boost.2283326.n4.nabble.com/Boost-Python-def-and-member-function-overloads-td2659648.html
and I end up doing something like this...
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(PlaySoundFromFile, Engine::PlaySound, 1, 3)
BOOST_PYTHON_MODULE(EngineModule)
{
class_<Engine>("Engine")
//Sound
.def("PlaySound", static_cast< void(Engine::*)(std::string, int, bool)>(&Engine::PlaySound));
}
The problem is I really have no idea how to use them together at the same time. I'd like to avoid having to change my base class function definitions.
Can someone who's done this before, or knows how to do this help me out?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这对我有用:
诀窍是您需要告诉每个
def()
使用一个重载说明符(这似乎是您所拥有的最大的缺失部分)。This works for me:
The trick is that you need to tell each
def()
to use one of the overload specifiers (that seemed to be the biggest missing piece from what you had).