大佬教程收集整理的这篇文章主要介绍了c – “最重要的const”与auto_ptr:为什么代码不能编译?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
#include <memory> struct A {}; std::auto_ptr<A> foo() { return std::auto_ptr<A>(new A); } const std::auto_ptr<A> bar() { return std::auto_ptr<A>(new A); } int main() { const std::auto_ptr<A> & a = foo(); // most important const const std::auto_ptr<A> & b = bar(); // error C2558: // class 'std::auto_ptr<_Ty>' : // no copy constructor available or copy // constructor is declared 'explicit' bar(); // No error? }
我期望“最重要的const”应用于变量“b”,然而,它不会编译,并且由于某种原因,编译器要求复制构造函数(这让我感到惊讶,因为这里不应该涉及复制) .对bar()的独立调用工作正常,这意味着,我猜,实际上b的初始化是问题所在.
注意:它在Visual C 2012,gcc 4.6和Solaris CC(所有编译器……)上编译,但不是gcc 3.4,也不是XL C)
以上是大佬教程为你收集整理的c – “最重要的const”与auto_ptr:为什么代码不能编译?全部内容,希望文章能够帮你解决c – “最重要的const”与auto_ptr:为什么代码不能编译?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。