#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>
などとのgetFieldによって返さないconst shared_ptr<const int>
としてタイプを推測しますか?自動車とconstオブジェクト
EDIT: MSVC2010
を参照してください? –
関連:http://stackoverflow.com/questions/7138588/c0x-auto-what-if-itit-a-constant-reference –