title: C++ iterator on a list error
body: <p>I have in a C++ class the following :
  I want to use an iterator to have an element of the questions list at a time by calling the getNextQuestion() function after checking if the iterator is still valid by calling isValid(). It gives me the following terrible error :</p>
  
  <pre><code>passing ‘const iterator {aka const std::_List_iterator&lt;domain::Question&gt;}’ as ‘this’ argument of ‘std::_List_iterator&lt;_Tp&gt;::_Self&amp; 
  std::_List_iterator&lt;_Tp&gt;::operator++() [with _Tp = domain::Question,std::_List_iterator&lt;_Tp&gt;::_Self = 
  std::_List_iterator&lt;domain::Question&gt;]’ discards qualifiers [-fpermissive]
  </code></pre>
  
  <hr>
  
  <pre><code>#ifndef TESTREPOSITORY_H_
  #define TESTREPOSITORY_H_
  
  #include &lt;iostream&gt;
  #include &lt;iterator&gt;
  #include &lt;list&gt;
  #include &lt;algorithm&gt;
  #include &lt;fstream&gt;
  #include "../domain/question.h"
  
  using namespace domain;
  
  namespace repository{
  template&lt;class T&gt;
  class TestRepository{
  std::string file;
  std::list&lt;T&gt; questions;
  typename std::list&lt;T&gt;::iterator it;
  public:
  TestRepository(std::string&amp; file=""):file(file){
      this-&gt;questions = this-&gt;getQ();
      this-&gt;it = this-&gt;questions.begin();
  };
  
  std::list&lt;T&gt; getQ() const{
      std::list&lt;T&gt; listq;
      using namespace std;
      string line;
      std::ifstream fin(file.c_str());
      while(fin.good()){
          Question q;
          fin &gt;&gt; q;
          listq.push_back(q);
      }
      fin.close();
      return listq;
  }
  
  const bool isValid() const{
      return this-&gt;it != this-&gt;questions.end();
  }
  
  const T getNextQuestion() const{
      T q = (*this-&gt;it);
      ++this-&gt;it;
      return q;
  }
  
  };
  }
  
  #endif /* TESTREPOSITORY_H_ */
  </code></pre>
  
  <p>Here is the code where I call these funcitons,maybe here is the problem coming from :</p>
  
  <pre><code>#include "TestController.h"
  #include "../domain/test.h"
  #include &lt;iostream&gt;
  #include &lt;list&gt;
  #include &lt;iterator&gt;
  
   namespace controller{
  
  TestController::TestController(repository::TestRepository&lt;domain::Question&gt;* repo,int   testId){
  this-&gt;repo = repo;
  this-&gt;testId = 0;
  }
  
  const test TestController::getCurrentTest() const{
  test test(this-&gt;testId,0,0);
  return test;
  }
  
  const bool TestController::isValid() const{
  return this-&gt;repo-&gt;isValid();
   }
  
  const Question TestController::getNextQuestion() const{
  return this-&gt;repo-&gt;getNextQuestion();
  }
  
  
  
  }
  </code></pre>