Swig生成的代码希望使用const初始化auto-ptr 引用,但auto ptr用非常数定义复制构造函数 参考,例如auto_ptr(auto_ptr&;)。生成的 代码不使用“discards const限定符”编译。当我手动 delete const编译fine限定符代码。在
我看到了很多邮件列表条目,但没有任何帮助。有人能吗 给我举个例子。我的非工作样本在这里:
%module auto_ptr_test
%{
#include <memory>
#include <iostream>
using namespace std;
%}
namespace std {
template <class T>
class auto_ptr {
auto_ptr();
auto_ptr(auto_ptr &);
T *operator->() const;
};
}
%inline %{
class Test {
Test() {
cout << "Test()" << endl;
}
public:
static std::auto_ptr<Test> create() const {
return auto_ptr<Test>(new Test());
}
void greet() {
cout << "hello" << endl;
}
};
%}
%template () std::auto_ptr<Test>;
我用cmake编译了它CMakeLists.txt文件公司名称:
^{pr2}$
我在libRETS中找到了提示,您需要根据每个方法进行:
http://code.crt.realtors.org/projects/librets/browser/librets/trunk/project/swig/auto_ptr_release.i?rev=HEAD
基本上,你想打开你从C++接收的AutoYPTR,然后在传递给C++之前把它包起来。要放入.i文件的代码示例如下:我不相信你能成功地用SWIG包装这段代码。问题是auto-u-ptr在复制时会更改所有权。这就是为什么它要求复制构造函数没有const。SWIG在内部管理对象所有权的方式意味着,如果没有大量自定义SWIG代码,您不太可能获得所需的所有权行为。在
相关问题 更多 >
编程相关推荐