Domanda

#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();
}

Nel codice sopra perché il compilatore deduce vtipo come come shared_ptr<int> e non come const shared_ptr<const int> Il tipo restituito da Getfield?

MODIFICARE:MSVC2010

Nessuna soluzione corretta

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top