Swig,Python,C++:TypeError:在方法'Geodatabase_Open'中,参数2的类型为'std::string
我刚接触C++和SWIG,这是我的第一个项目。
我能顺利地用distutils构建我的Python扩展。但是,当我尝试使用我的对象时,总是遇到这个错误。
看起来是从Python字符串转换成std::string时出现了问题。
我在Windows 7上工作,使用的是Visual Studio C++ 2008 Express。
这是我的swig接口文件:
/* swig interface file */
%module Geodatabase
%{
#include Geodatabase_helper.h
%}
namespace FileGeodatabase {
class Geodatabase {
public:
Geodatabase();
Geodatabase(std::string p);
~Geodatabase();
void Open(std::string p);
void Close();
};
}
1 个回答
4
根据swig的文档,如果你想使用std::string
,你需要加上%include "std_string.i"
这行代码。
%module example
%include "std_string.i"
std::string foo();
void bar(const std::string &x);