使用boost.python将模板函数从C++导出为python的正确方法是什么?下面是代码:导出模板函数
template<typename T>
T getValue(const std::string &key, const T &defaultValue = T()) {}
// Export into some python class:
class_<ConfigManager>(...)
.def("GetValue", getValue<int>)
.def("GetValue", getValue<float>)
.def("GetValue", getValue<std::string>);
与用法:
print GetValue("width")
Boost.Python.ArgumentError: Python argument types in
GetValue(ConfigManager, str)
did not match C++ signature:
GetValue(ConfigManager {lvalue}, std::string, int)
有什么不对?
在什么范围是getValue?它是一个类成员函数还是静态方法? – zdan 2011-03-18 20:39:31
@zdan是其班级成员。我隐瞒了这部分,以获得更少的代码。 – Ockonal 2011-03-18 20:45:27