title: stack overflow when using copy constructor and/or assignment operator with string in c++
body: <p>i'm trying to run insertion sort on a simple class of my own making, which features a couple fields (int, float, and string) as well as a copy constructor, assignment operator, and '>' operator. </p>
  
  <p>however, i'm getting a stack overflow when i run the code below. visual studio tells me its coming from the getName() function in my 'Student' class. the error originates from the assignment in my insertion sort function <code>arr[i + 1] = arr[i];</code> </p>
  
  <p>anyone know why this is? i'm relatively new to c++, coming from mostly a java background. </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;string&gt;
  using namespace std;
  
  class Student {
  public:
      Student(string nm, int ID, float avg): name(nm), studentID(ID), overallAverage(avg) {}
  
      Student(const Student&amp; rhs) : name(rhs.getName()), studentID(rhs.getStudentID()), overallAverage(rhs.getOverallAverage()) {}
  
      // copy and swap idiom
      Student&amp; operator=(const Student&amp; rhs) {
          Student copy = rhs;  // places a copy of rhs into copy using the copy constructor (copy will be cleaned up on return)
          swap(*this, copy); // move copy or rhs into this, this is a pointer to current object, *this dereferences the pointer
          return *this; 
      }
      ~Student() {}
  
      bool operator&gt;(const Student&amp; rhs) {
          if (rhs.getOverallAverage() &gt; overallAverage)
              return false;
          else return true; 
      }
  
      string getName()const { return name; }
      int getStudentID()const { return studentID;  }
      float getOverallAverage()const { return overallAverage; }
  
  private:
      string name; 
      int studentID; 
      float overallAverage; 
  
  };
  
  template&lt;typename T&gt; 
  vector&lt;T&gt;&amp; insertionSort(vector&lt;T&gt;&amp; arr){
      for (int j = 1; j &lt; arr.size(); j++) {
          T key = arr[j]; 
          int i = j - 1; 
          while (i &gt; -1 &amp;&amp; arr[i] &gt; key) {
              arr[i + 1] = arr[i]; 
              i = i - 1; 
          }
          arr[i + 1] = key; 
      }
      return arr; 
  }
  
  
  int main()
  {
      vector&lt;Student&gt; students = {Student("russ",0,89),Student("Seb",1,75),Student("julia",2,85),
                                  Student("johnny",3,90),Student("Sushma",4,55)}; 
  
      students = insertionSort(students); 
  
      for (int i = 0; i &lt; students.size(); i++) {
          cout &lt;&lt; students[i].getName() &lt;&lt; ", ";
      }
      cout &lt;&lt; endl;  
  }
  </code></pre>
  
  <p>original operator= from txtbook i'm using:</p>
  
  <pre><code>IntCell &amp; operator= ( const IntCell &amp; rhs ) // Copy assignment
  {
  IntCell copy = rhs;
  std::swap( *this, copy );
  return *this;
  }
  </code></pre>