title: How to fix overloading increment and + operator and ending up with segmentation fault?
body: <p>I've looked through a few articles that seem similar to my problems that I'm having on my homework for intro to C++, but am still unable to find a solution.</p>
  
  <p>I'm attempting to overload the operator+ to increase the passenger capacity by a int n. Also, overloading the operator++ to increase the passenger capacity by 1.</p>
  
  <p>Note that polymorphism is happening in my class, I have Ship (base), CruiseShip (derived).</p>
  
  <p>CruiseShip constructor:</p>
  
  <pre><code>CruiseShip::CruiseShip(string name, string year, int passengers) : Ship(name, year)
  {
      maxPassengers = passengers;
  }
  </code></pre>
  
  <p>Operator overloads:</p>
  
  <pre><code>CruiseShip&amp; CruiseShip::operator+(int n) const
  {
      maxPassengers += n;
      return *this;
  }
  
  CruiseShip&amp; CruiseShip::operator++() // prefix
  {
      ++maxPassengers;
      return *this;
  }
  
  CruiseShip CruiseShip::operator++(int) // postfix
  {
      CruiseShip temp(*this);
      operator++();
      return temp;
  }
  </code></pre>
  
  <p>Main:</p>
  
  <pre><code>int main()
  {
  
  //Create objects, pointers
  Ship *ships[3] = {new Ship("Titania", "2020"), new CruiseShip("Lusia", "2029", 200), new CargoShip("Luvinia", "2025", 500)};
  
  //Print out ships
  for(Ship *s : ships)
  {
      s -&gt; print();
      cout &lt;&lt; endl;
  }
  
  //Reset a ships passenger, capacity
  //I've tried testing each individually and all 3 still end up with segmentation errors
  ships[1] = ships[1] + 5; //segmentation error related to this
  ships[1]++; // segmentation error related to this
  ++ships[1]; // segmentation error related to this
  
  //Print out ships
  for(Ship *s : ships)
  {
      s -&gt; print();
      cout &lt;&lt; endl;
  }
  
  //deallocate
  return 0;
  }
  </code></pre>