title: Return pointers, return values or pass in references, which is elegant in C++?
body: <p>I'm confused in how to deal with a function that intends to return a class object.  </p>
  
  <p>Here I have a function <code>connect</code> which accepts a url in the form of a char array and then creates an object of class Response which contains the response of visiting this url to return.  </p>
  
  <p>1> Return the response by value is the most straightforward, but people say copy constructor will make return by value kind of slow:  </p>
  
  <pre><code>Response connect(char *); // declaration of connect  
  Response resp = connect(url_str);  
  </code></pre>
  
  <p>2> Return the response by pointer is also easy to read, but need to handle deleting the pointer outside <code>connect</code>:  </p>
  
  <pre><code>Response * connect(char *);  // declaration of connect  
  Response * resp = connect(url_str);  
  </code></pre>
  
  <p>3> Declare an object of class Response before calling <code>connect</code> and pass it into <code>connect</code> via reference is good in reducing the risk of memory-leaks and also faster than return by value, but this makes the code counter-intuitive:  </p>
  
  <pre><code>void connect(char *, Response &amp;); // declaration of connect  
  Response resp;  
  connect(url_str, resp);  
  </code></pre>
  
  <p>How will you handle this kind of case in C++? Any suggestion or experience are welcome.</p>