提升Python - 具有默认参数问题的重载函数
Boost Python - Overloaded Functions with default arguments problem
我有一个类,它有两个函数,它们都采用一组不同的参数,并且都有这样的默认参数:
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));
}
问题是我真的不知道如何同时使用它们。我想避免更改基类函数定义。
以前做过这件事的人,或者知道如何做到这一点的人可以帮助我吗?
提前致谢
这对
我有用:
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(
PlaySoundFromFile, Engine::PlaySound, 1, 3)
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(
PlaySoundFromFMOD, Engine::PlaySound, 1, 2)
BOOST_PYTHON_MODULE(EngineModule)
{
class_<Engine>("Engine")
.def("PlaySound", static_cast< void(Engine::*)
(const std::string&, int, bool)>
(&Engine::PlaySound), PlaySoundFromFile())
.def("PlaySound", static_cast< void(Engine::*)
(FMOD::Sound*, int)>
(&Engine::PlaySound), PlaySoundFromFMOD())
;
}
诀窍是你需要告诉每个def()
使用其中一个重载说明符(这似乎是你所拥有的中最大的缺失部分)。
相关文章:
- 一个关于在C++中重载布尔运算符的问题
- 在C++中使用重载提取运算符时出现问题
- 重载运算符与添加问题
- 加、乘、除、减复数的问题 C++ - 运算符重载
- 0xC0000005:访问冲突读取位置 0x00000000. 重载 == 运算符的问题
- 关于重载 -> 运算符中 const 关键字的特定位置的问题
- 基于 SFINAE 的特征实现问题与函数模板重载
- 关于在成员重载中使用 std::move() 的问题
- 字符 * 未从重载运算符或内存管理问题正确返回
- constexpr 运算符重载使用参数的问题
- c++中重载输入运算符的问题
- 在C++中写入 4D 矢量时遇到问题(没有可行的重载"=")
- 我的重载函数有什么问题?
- C++使用模板参数来解决重载问题
- C++ 中重载成员函数的问题
- 我想知道我将如何实现 + 运算符重载.我已经从我上一个问题中计算出 += 运算符重载
- 为什么C++在自定义结构向量时会出现 ostream 重载问题?
- 解决 CRTP 函数重载歧义问题
- C++:创建线程时出现问题;错误 C2672:"std::invoke":找不到匹配的重载函数
- C++重载构造函数问题