title: Object C++ tab[i] new object values assign
body: <p>When I try to assign values in main() to tab[i] I get memory leak. You can change anything in code, but class need to stay as string, string, double and &quot;K2 tab[4];&quot; stay as it is. Under main() you have a view on data.txt file.</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  using namespace std;
  
  class K2 {
      string* words;
      double number;
  
  public:
      K2() :words(nullptr), number(0.0) {}
      K2(const string&amp; a1, const string&amp; a2, const double&amp; a3) :number(a3) {
          words[0] = a1;
          words[1] = a2;
      }
  
      K2&amp; operator=(const K2&amp; r) {
          words[0] = r.words[0];
          words[1] = r.words[1];
          number = r.number;
          return *this;
      }
  
  friend
  ostream&amp; operator&lt;&lt;(ostream&amp; out, const K2&amp; r);
  };
  ostream&amp; operator&lt;&lt;(ostream&amp; out, const K2&amp; r) {
      return out &lt;&lt; r.words[0] &lt;&lt; &quot; &quot; &lt;&lt; r.words[1] &lt;&lt; &quot; &quot; &lt;&lt; r.number &lt;&lt; endl;
  }
  
  int main() {
      K2 tab[4];
  
      string a, b;
      double c;
      ifstream file;
      file.open(&quot;data.txt&quot;);
      for (int i = 0; i &lt; 4; i++) {
          file &gt;&gt; a &gt;&gt; b &gt;&gt; c;
          tab[i] = K2 (a, b, c); // &lt;- memory leak
      }
      file.close();
  }
  /*
  data.txt:
  white coffe 3.50
  black tea 1.50
  orange juice 3.00
  dark chocolate 5.25
  */
  </code></pre>