c – auto_ptr无法正常工作 – 编译错误

c – auto_ptr无法正常工作 – 编译错误,第1张

概述大规模编辑: 在juanchopanza建议之后,我设法得到了这个最小的例子: #include <memory>struct a{ int b;};int main(){ typedef std::auto_ptr<a> ArgAutoPtr; ArgAutoPtr floatingArg; floatingArg = ArgAutoPtr( n 大规模编辑:

在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引用不能绑定到临时引用.

总结

以上是内存溢出为你收集整理的c – auto_ptr无法正常工作 – 编译错误全部内容,希望文章能够帮你解决c – auto_ptr无法正常工作 – 编译错误所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1216064.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存