【发布时间】:2019-02-20 16:21:27
【问题描述】:
我想将以下 C++ 代码包装到 python 模块中。
class minimal
{
public:
minimal()
{
}
~minimal()
{
}
template<class T>
void foo(T a)
{
auto z = a;
}
};
如您所见,我有模板函数,并且我知道我不能在 Python 中调用模板函数,但是我希望由于类型推导,使用 int 或字符串参数调用 foo 会成功。 .cxx 文件中仍然没有 foo,但 SWIG 文档说,它支持类型推导
所以我的目标是像这样编写 python 代码:
#C++ analog: minimal.foo(123)
minimal().foo(123)
#C++: to minimal().foo(0.1)
minimal().foo(0.1)
有可能吗?还是我的想法完全错误?
【问题讨论】: