vendredi 1 avril 2016

No pointer type error for shared_ptr<>

I am using this method to get a shared_ptr<> from an object:

virtual std::shared_ptr<Bar<T>> iterator() const override{
        auto iter = std::make_shared<Foo>(Foo(*this));
        return iter;
    }

where Bar is a a base class of Foo. Foo isnt a template class, while Bar is. I am getting an error here:

auto i = object.iterator();
while (i->hasNext()){
        std::cout << i->next()<<std::endl;
    }

which says:

error: base operand of '->' has non-pointer type 'std::shared_ptr<Bar<int> >'
     while (i->hasNext()){
             ^

since shared_ptr should support the -> operator I don't realy understand why I am getting this error.

Edit: Foo is an inner class of an class Stack like this:

template<typename T>
class Stack{
public:
    virtual std::shared_ptr<Bar<T>> iterator() const override{
            auto iter = std::make_shared<Foo>(Foo(*this));
            return iter;
        }

private:
    class Foo: Bar<T>{
    };
};

Aucun commentaire:

Enregistrer un commentaire