title: c++ taking the address of a temporary object
body: <p>I have two code segments which I expected the same outcome:</p>
  
  <p>First one:</p>
  
  <pre><code>SomeClass somefunc(...){
      SomeClass newObj;
      //some codes modify this object
      return newObj;
  }
  
  int main(){
      SomeClass *p;
      p = &amp;(somefuc(...));
  }
  </code></pre>
  
  <p>Second one:</p>
  
  <pre><code>SomeClass *somefunc(...){
      SomeClass newObj;
      //some codes modify this object
      return &amp;newObj;
  }
  
  int main(){
      SomeClass *p;
      p = somefunc(...);
  }
  </code></pre>
  
  <p>Why is it I got a "taking the address of a temporary object" error when I tried to build the first code segment, while the second code segment doesn't produce an error?</p>