I tried to overload (c)begin/(c)end functions for a class so as to be able to call C++11 range-based for loop.
It works in most of the cases, but I don't manage to understand and solve one :
for (auto const& point : fProjectData->getPoints()){ ... }
This line returns error:
Error C2662: 'MyCollection<T>::begin' : cannot convert 'this' pointer from 'const MyCollection' to 'MyCollection<T> &'
because fProjectData is a pointer to const. If I make it non-const, it does work. I don't understand why, considering that cbegin() & cend() are developped with exactness as begin() & end() functions.
Here are my functions developped (in the header file) in MyCollection:
/// \returns the begin iterator
typename std::list<T>::iterator begin() {
return objects.begin();
}
/// \returns the begin const iterator
typename std::list<T>::const_iterator cbegin() const {
return objects.cbegin();
}
/// \returns the end iterator
typename std::list<T>::iterator end() {
return objects.end();
}
/// \returns the end const iterator
typename std::list<T>::const_iterator cend() const {
return objects.cend();
}
Any ideas?