title: C++ reference to local temporary object
body: <p>Consider the following template class  </p>
  
  <pre><code>template &lt;typename T&gt;
  class A {
  public:
      virtual T const&amp; getContent() = 0;
  };  
  </code></pre>
  
  <p>I derive this class using 'int*' as type 'T', as follows</p>
  
  <pre><code>class A1 : public A&lt;int*&gt; {
  private:
      int a;
  public:
      int* const&amp; getContent() { return &amp;a; }
  };
  </code></pre>
  
  <p>I got the following warning: 'returning reference to local temporary object'.</p>
  
  <p>Questions:  </p>
  
  <ol>
  <li><p>Does the compiler implicitly instantiate a local temporary object of type 'int * const' from '&amp;a' before returning its reference?</p></li>
  <li><p>As I do know that A.a really exists, then can I just ignore this warning? Will there be any undesirable side-effects of using this code?</p></li>
  <li><p>What is the proper way of handling this situation? Do I need to work with the member variable 'int *a' instead. This would be cumbersome.</p></li>
  </ol>