大佬教程收集整理的这篇文章主要介绍了c – auto和const对象,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
#include <iostream> #include <boost/shared_ptr.hpp> using namespace std; class A { public: const shared_ptr<const int> getField () const { return field_; } private: shared_ptr<int> field_; }; void f(const A& a) { auto v = a.getField(); //why auto doesn't a const shared_ptr<const int> here ? v.reset(); //OK: no compile error } int main() { A a; f(a); std::cin.ignore(); }
在上面的代码中,为什么编译器将v的类型推导为shared_ptr< int>而不是const shared_ptr< const int> getField返回的类型?
编辑:@H_3_10@mSVC2010
以上是大佬教程为你收集整理的c – auto和const对象全部内容,希望文章能够帮你解决c – auto和const对象所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。