title: Properly return a unique ptr
body: <p>I am writing a String class <code>MyString</code> (yes, as homework) and have to offer a <code>toCString</code> method which returns a <code>unique_ptr&lt;char[]&gt;</code> (and not a <code>Vector</code>). Unfortunately I fail when returning the pointer to the caller: The result is always filled with wrong content - it seems that I create the pointer and/or the character array on the stack.</p>
  
  <pre><code>unique_ptr&lt;char[]&gt; MyString::toCString() const {
       char *characters = new char[m_len];
       char *thisString = m_string.get();
       for (int i = 0; i &lt; m_len; i++) {
           characters[i] = *(thisString + m_start + i);
       }
       const unique_ptr&lt;char[], default_delete&lt;char[]&gt;&gt; &amp;cString = unique_ptr&lt;new char[m_len]&gt;(characters);
       return cString;
  }
  </code></pre>
  
  <p>When debugging I always get expected behaviour. Problems only occur on callers site. Where is my mistake?</p>