我有一个具有以下原型的构造函数:
YCPTerm(const string& s);
YCPTerm(const string& s, const YCPList& l);
YCPTerm(bytecodeistream & str);我正在使用swig来生成python绑定。在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 &)我发现了这个答案,这似乎是一个类似的问题,但排版排版对我不起作用。
这就是我试过的:
%typemap(typecheck,precedence=141) const std::string& str {
$1 = Z_TYPE_PP($input) == IS_STRING;
}我该怎么解决这个问题?是否需要输入和输出类型图来转换值?我一直是阅读有关打字机地图的资料,不知道如何打印一个const字符串&。
发布于 2017-10-05 18:34:41
std_string.i库包括在std::string和Python之间来回转换的类型。有关更多详细信息,请参阅SWIG中的std::string库的文档。
发布于 2017-10-03 15:24:45
我找到了回答这里。
将这些行添加到我的.i文件中修复了错误:
%include std_string.i
%inline %{
using namespace std;
%}我不明白为什么。也许别人能回答这个问题。
https://stackoverflow.com/questions/46547561
复制相似问题