【发布时间】:2012-01-21 14:35:09
【问题描述】:
#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 返回的类型?
编辑: MSVC2010
【问题讨论】: