title: Put a stack-allocated function return value into a unique_ptr
body: <p>I came across this problem whilst working within Qt, but the types do not matter; it is the general form of the C++ language that I am confused about.</p>
  
  <p>I want to have a </p>
  
  <p><code>std::unique_ptr&lt;QSqlDatabase&gt; database;</code></p>
  
  <p>There is a function with this signature</p>
  
  <p><code>QSqlDatabase QSqlDatabase::addDatabase()</code></p>
  
  <p>I tried to do something like</p>
  
  <p><code>database.reset(QSqlDatabase::addDatabase());</code></p>
  
  <p>Of course this failed to compile, because <code>database</code> expects a <code>QSqlDatabase *</code> and the method call returns a simple <code>QSqlDatabase</code>. What do I do if I want to put the return value of <code>addDatabase()</code> into a <code>unique_ptr</code>? I am stuck because in no place am I using the heap.</p>