我有一个具有这些原型(prototype)的构造函数:
YCPTerm(const string& s);
YCPTerm(const string& s, const YCPList& l);
YCPTerm(bytecodeistream & str);
我正在使用 swig 生成 python 绑定(bind)。在 python 中,我尝试调用构造函数,并得到:
>>> import ycp
>>> ycp.YCPTerm("Empty")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "ycp.py", line 575, in __init__
this = _ycp.new_YCPTerm(*args)
NotImplementedError: Wrong number or type of arguments for overloaded function 'new_YCPTerm'.
Possible C/C++ prototypes are:
YCPTerm::YCPTerm(string const &)
YCPTerm::YCPTerm(string const &,YCPList const &)
YCPTerm::YCPTerm(bytecodeistream &)
我找到了this answer这似乎是一个类似的问题,但类型映射类型检查对我不起作用。
这是我尝试过的:
%typemap(typecheck,precedence=141) const std::string& str {
$1 = Z_TYPE_PP($input) == IS_STRING;
}
如何解决这个问题?我是否需要输入和输出类型映射来转换值?我去过reading about typemap's here ,并且不确定如何类型映射 const string&。
请您参考如下方法:
std_string.i 库包含在 std::string 和 Python 字符串之间进行来回转换的 typedef。请参阅the documentation on the std::string library in SWIG了解更多详情。






