title: addition assignment overloading dynamically allocated pointer to array of class objects c++
body: <p>first time posting. Thanks in advance for your correspondence and patience.</p>
  
  <p>I need to prevent the copy of an object, if that object already exists in my array.</p>
  
  <p>I am beyond my depth as how to compare these values and prevent copy.</p>
  
  <p>My next step is trying: <code>unique_ptr</code> or <code>shared_ptr</code> or <code>compare()</code> or <code>iterator</code>.</p>
  
  <p>NO VECTORS.... I NEED TO ALLOCATE AND DE-ALLOCATE EVERYTHING.</p>
  
  <p>ConfirmationSender.h</p>
  
  <pre class="lang-cpp prettyprint-override"><code>class ConfirmationSender {
      Reservation** ppCon;
      size_t cCnt;
  public:
      ConfirmationSender();
      ~ConfirmationSender();
      ConfirmationSender&amp; operator+=(const Reservation&amp; res);
      // ConfirmationSender&amp; operator-=(const Reservation&amp; res);
      void display(std::ostream&amp; os) const;
  };
  
  std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const ConfirmationSender&amp; obj);
  </code></pre>
  
  <p>ConfirmationSender.cpp</p>
  
  <pre class="lang-cpp prettyprint-override"><code>ConfirmationSender&amp; ConfirmationSender::operator+=(const Reservation&amp; res) {
      if (cCnt == 0) {
          ++cCnt;
          ppCon = new Reservation* [cCnt];
          ppCon[0] = new Reservation(res);
      }
      else {
          Reservation** temp1 = nullptr;
          temp1 = new Reservation * [cCnt];
  
          for (size_t i = 0; i &lt; cCnt; i++) {
              temp1[i] = ppCon[i];
          }
  
          ++cCnt;
  
          delete[] ppCon;
          ppCon = new Reservation * [cCnt];
  
          for (size_t i = 0; i &lt; cCnt - 1; i++) {
              ppCon[i] = temp1[i];
          }
          ppCon[cCnt - 1] = new Reservation(res);
  
          delete[] temp1;
          temp1 = nullptr;
  
          /*
          NEED TO IMPLEMENT CONDITION
          SO THE VALUE I COPY 
          CANNOT BE A VALUE ALREADY EXISTING IN ARRAY
          */
      }
  
      return *this;
  }
  </code></pre>
  
  <pre class="lang-cpp prettyprint-override"><code>class Reservation {
      std::string id, name, email;
      int seats, day, hour;
  
  public:
      Reservation();
      Reservation(const std::string&amp; m_res);
      void display(std::ostream&amp; os) const;
  };
  
  std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const Reservation&amp; obj);
  </code></pre>
  
  <pre class="lang-cpp prettyprint-override"><code>Reservation::Reservation() {
      seats = 0;
      day = 0;
      hour = 0;
  };
  
  Reservation::Reservation(const std::string&amp; m_res) {
      std::string t_str;
      t_str = m_res;
      t_str.erase(std::remove(t_str.begin(), t_str.end(), ','), t_str.end());
  
      istringstream iss(t_str);
      std::string buffer = {};
      static int count = 0;
  
      while (iss &gt;&gt; buffer) {
          switch (count % 6) {
              case 0: id = buffer; break;
              case 1: name = buffer; break;
              case 2: email = buffer; break;
              case 3: seats = atoi(buffer.c_str()); break;
              case 4: day = atoi(buffer.c_str()); break;
              case 5: hour = atoi(buffer.c_str()); break;
          }
          count++;
      }
      buffer.clear();
      iss.str(std::string());
  }
  
  void Reservation::display(std::ostream&amp; os) const {
      string menu_type;
  
      if (hour &gt;= 6 &amp;&amp; hour &lt;= 9) { menu_type = "Breakfast"; }
      else if (hour &gt;= 11 &amp;&amp; hour &lt;= 15) { menu_type = "Lunch"; }
      else if (hour &gt;= 17 &amp;&amp; hour &lt;= 21) { menu_type = "Dinner"; }
      else { menu_type = "Drinks"; }
  
      os &lt;&lt; "Reservation "
          &lt;&lt; id &lt;&lt; " "
          &lt;&lt; name &lt;&lt; " &lt;"
          &lt;&lt; email &lt;&lt; "&gt; "
          &lt;&lt; menu_type &lt;&lt; " on day "
          &lt;&lt; day &lt;&lt; " @ "
          &lt;&lt; hour &lt;&lt; ":00 for "
          &lt;&lt; seats &lt;&lt; " people." &lt;&lt; '\n';
  }
  
  std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const Reservation&amp; obj) {
      obj.display(os);
      return os;
  }
  </code></pre>
  
  <p>main.cpp</p>
  
  <pre class="lang-cpp prettyprint-override"><code>// Confirmation Sender
  {
      std::cout &lt;&lt; "CS: Testing Operators\n";
      std::cout &lt;&lt; "==========================\n";
      sender1 += *ppReservations[5];
      sender1 += *ppReservations[16];
      sender1 += *ppReservations[16];
      // THE SECOND [16] SHOULD NOT BE COPIED BY ADDITION OPERATOR
      std::cout &lt;&lt; sender1;
      std::cout &lt;&lt; "==========================\n\n";
  }
  </code></pre>