Problem with Boost bidirectionnal iterator not writable
I try to make bidirectionnal iterators with Boost Iterator. I have implemented some functions as suggested in the documentation here.
I have a parent class where the funct开发者_开发百科ions to implement are declared pure virtual (I need polymorphic iterators). For the moment, I have one inherited class where the functions are implemented. Moreover, I use boost::bidirectional_traversal_tag.
The dereference() function is implemented as follows in the inherited class:
template <typename T>
T& ImageIterator_NotPlanar<T>::dereference() const {
return *((T*)buffer);
}
to read values as the following example, it works perfectly:
for (; !iter.isEndReached(); ++iter)
cout << "ITERATOR INC: " << *iter << endl;
(where isEndReached() is a personal function). The problem is that the following code doesn't works:
*iter = 3;
g++ returns the following error:
lvalue required as left operand of assignment
What is wrong ?
Thanks
We need to see exactly where the error is generated. Also, we have to assume you have the proper non-const version
Could it be you need to have
template <typename T>
T& ImageIterator_NotPlanar<T>::dereference() {
return *((T*)buffer);
}
template <typename T>
T const& ImageIterator_NotPlanar<T>::dereference() const {
return *((T*)buffer);
}
精彩评论