title: How to push_back to a list with getter function?
body: <p>I have getter setter function like this.</p>
  
  <pre><code>void Student::setStudentName(std::__cxx11::string b)
  {
      cout&lt;&lt;"Enter the student name"&lt;&lt;endl;
      cin &gt;&gt; studentName;
      int size = b.size();
      if(size &gt; 0 &amp;&amp; size&lt;20)
          studentName = b;
      else
          cout&lt;&lt;"Please enter a name between 1-20 char"&lt;&lt;endl;
  }
  string Student::getStudentName() const
  {
      return studentName;
  }
  </code></pre>
  
  <p>What i want to do is add to the list with getter function.</p>
  
  <pre><code>void Student::addStudent()
  {
      int studentAdd;
      cout&lt;&lt;"How many student do you want to add?"&lt;&lt;endl;
      cin&gt;&gt;studentAdd;
  
      for(int i=0;i&lt;studentAdd;++i)
      {
          setStudentName("a");
          getStudentList().push_back(getStudentName());
      }
  }
  </code></pre>
  
  <p>I tried like this but</p>
  
  <pre><code>getStudentList().push_back(getStudentName()); 
  </code></pre>
  
  <p>this code didn't work. What could be the problem? </p>
  
  <p>And here is the list's getter/setter</p>
  
  <pre><code>void Student::setStudentList(list&lt;string&gt; a)
  {
      studentList = a;
  }
  list&lt;string&gt; Student::getStudentList() const
  {
      return studentList;
  }
  </code></pre>