title: returning address or local variable or temporary C++ warning
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2862494/c-warning-address-of-local-variable">c++ warning: address of local variable</a>  </p>
  </blockquote>
  
  
  
  <p>Hi,
  When i write this code:</p>
  
  <pre><code>//Returns the transpose matrix of this one
  SparseMatrix&amp; SparseMatrix::transpose()const{
      vector&lt;Element&gt; result;
      size_t i;
      for(i=0;i&lt;_matrix.size();++i){
          result.push_back(Element(_matrix.at(i)._col, _matrix.at(i)._row, _matrix.at(i)._val));
      }
  
      return SparseMatrix(numCol,numRow,result);
  }
  </code></pre>
  
  <p>I get the warning "returning address or local variable or temporary". The last line calls the SparseMatrix constructor. I don't understand what's wrong with this code, and how can i fix it so i can return a SparseMatrix object as i want.</p>