
Nathan Ridge wrote:
From: avishay.ben.shabtai@gmail.com
Hi i have a container class that defines 2 overloaded [] operators: T& operator[](const chat *); T& operator[](unsigned int);
when i am using BOOST_FOREACH(T val,container)
i get compilation errors but working directly with iterators is working ok, any idea?
BOOST_FOREACH uses the begin() and end() member functions to get iterators pointing to the beginning and end of the range, then advances the begin iterator using ++ until it reaches the end. Along the way it dereferences the iterator to get the the element that is assigned to "val". It has nothing to do with operator[].
If you want your container to work with BOOST_FOREACH, you need to make sure it has begin() and end() member functions which return iterators with the appropriate capabilities (increment, dereference, equality comparison).
Or specialized boost::begin/boost::end perhaps? Jeff