Boost logo

Boost Users :

Subject: [Boost-users] [iterator] error while accessing member of result of brackets-operator
From: Sebastian Pfützner (s.pfuetzner_at_[hidden])
Date: 2014-01-09 10:37:06


Hello,

the following code does not compile with the last line in main(). The
error message is

main.cpp: In function 'int main()':
main.cpp:37:8: error: 'boost::detail::operator_brackets_result<It, S,
S&>::type' has no member named 'i'
   it[3].i = 0;
         ^

What could be the problem?

#include <boost/iterator/iterator_facade.hpp>

struct S
{
        int i;
        float f;
};

class It :
        public boost::iterator_facade<It, S, boost::random_access_traversal_tag>
{
private:
        friend class boost::iterator_core_access;

        static S s;

        reference dereference() const
        { return s; }

        bool equal(It const&) const
        { return true; }

        void increment() {}
        void decrement() {}
        void advance(difference_type n) {}

        difference_type distance_to(It const&) const
        { return 0; }
};

int main()
{
        It it;
        (*(it + 3)).i = 0;
        S& s = it[3];
        s.i = 0;
        it[3].i = 0;
}

-- 
Sebastian Pfützner
s.pfuetzner_at_[hidden]
ICQ-ID: 39965036

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net