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