title: C++ Save pointer of object created in function
body: <p>I have struct called Rectangle:</p>
  
  <pre><code> struct Rectangle {
      std::vector&lt;float&gt; m_min;
      std::vector&lt;float&gt; m_max;
      exType timeOfArrival, timeOfexpiry;
      unsigned int id;
  };
  </code></pre>
  
  <p>In a function I pass a rectangle by value and save the object into a DB. I want to return the pointer of the rectangle so that I can use it out of the function and save it (the pointer) in a vector. From what I have read as of C++11 there is no need to return a pointer so I return the rectangle. Is this the right way? How can I have the pointer to the object created in the function?</p>
  
  <p>This is how I do it now:</p>
  
  <pre><code>Rectangle Insert(Rectangle rect){// "Insert" is a function of another class
      SaveIntoToDB(rect);// Calls other functions that use reference
      return rect;
  }
  </code></pre>
  
  <p>I need something fast that does not create duplicates in memory.</p>