title: cpp- Attempt to take address of value not located in memory
body: <p>I have a class with the following private member:</p>
  
  <pre><code>class Student
  {
       public:
          Student(std::string name_ , int const id_);
          virtual ~Student();
          void addGrade(int const grade2add);//grade above 100
  
      private:
          std::string name;  //max 20 chars
          int const id; //5 digits, only digits
          std::vector&lt;int&gt; grades;
          static int  maxGrade;
          static int freq_grades[100];
  
  };
  </code></pre>
  
  <p>I have to check that the lentgh of the id is equal to 5 and contains only digit.
  I checked it in the constructor in the following way:</p>
  
  <pre><code>Student::Student(std::string name_, int const id_): name(name_), id(id_)
  {
      string idStr=to_string(id);
      if (name.size()&gt;=20)
      {
          throw(121);
          //cout&lt;&lt;"Name should be less than 20 chars"&lt;&lt;endl;
      }
      if (idStr.size()!=5)
      {
          throw(122);
           //cout&lt;&lt;"Id should be 5 nums"&lt;&lt;endl;
      }
      if (!all_of(idStr.begin(), idStr.end(),  ::isdigit))
      {
          throw(123);
      }
  }
  </code></pre>
  
  <p>The program exit because the condition of the size (thogh the input is 12345, so it suppose to be legal). When I debug and watch isStr.size() I got "Attempt to take address of value not located in memory."</p>