c – auto_ptr无法正常工作 – 编译错误
发布时间:2020-12-16 09:52:27 所属栏目:百科 来源:网络整理
导读:大规模编辑: 在juanchopanza建议之后,我设法得到了这个最小的例子: #include memorystruct a{ int b;};int main(){ typedef std::auto_ptra ArgAutoPtr; ArgAutoPtr floatingArg; floatingArg = ArgAutoPtr( new a );} 这给了我错误: no match for 'opera
大规模编辑:
在juanchopanza建议之后,我设法得到了这个最小的例子: #include <memory> struct a{ int b; }; int main() { typedef std::auto_ptr<a> ArgAutoPtr; ArgAutoPtr floatingArg; floatingArg = ArgAutoPtr( new a ); } 这给了我错误: no match for 'operator=' in 'm_floatingArg = std::auto_ptr<a>(((a*)operator new(4u)))' QNX 6.4.1与GCC 4.3.3 编辑 我设法像这样编译它.这是否按预期工作或将生成…无论恶魔auto_ptr生成什么? ArgAutoPtr floatingArg2 = ArgAutoPtr( new a ); floatingArg = floatingArg2; 解决方法
表达式ArgAutoPtr(new a)正在创建临时auto_ptr.
auto_ptr :: operator =对其参数采用非const引用,与operator =的每个其他示例不同.非const引用不能绑定到临时引用. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |