在一些test.i文件中,我有以下功能:
std::auto_ptr<std::string> test(int arg1, int arg2)
{
std::return innerTest(arg1);
}
std::auto_ptr<std::string> innerTest(int arg)
{
std::string("Non-const");
std::auto_ptr<std::string> ret(&str);
return ret;
}
我收到以下错误:
error: passing ‘const std::auto_ptr<std::basic_string<char> >’ as ‘this’
argument of ‘std::auto_ptr<_Tp>::operator std::auto_ptr_ref<_Tp1>()
[with _Tp1 = std::basic_string<char>; _Tp = std::basic_string<char>]’ discards qualifiers
在生成的test_wrap.cxx文件中,我找到:
resultobj = SWIG_NewPointerObj((new std::auto_ptr< std::string >
(static_cast< const std::auto_ptr< std::string >& >(result))),
SWIGTYPE_p_std__auto_ptrT_std__string_t, SWIG_POINTER_OWN | 0 );
为什么要尝试转换为const std::auto_ptr<std::string>
来构建std::auto_ptr<std::string>
,如何让它不这样做呢?