Is assigning a reference to a reference a valid operation?
<p>I have the following code:</p>

<pre><code>void cStatisticDBSerializer::GetStats (std::map &lt;std::string, long long &gt;&amp; ioCounterStats,
                                       std::map &lt;std::string, long long &gt;&amp; ioGaugeStats,
                                       bool iSwitch)
{
   // Before getting the stats, clear the containers 
   ioCounterStats.clear ();
   ioGaugeStats.clear ();

   std::map &lt;std::string, long long &gt;&amp; lStats = ioCounterStats;

   if (iSwitch)
   {
      lStats = ioGaugeStats;
   }

   // Do something with lStats
}
</code></pre>

<p>The question is: Is it valid to assign the function input reference to the local variable lStats?  For some reason, this compiles fine, but does not behave as expected.  However, if I change lStats to a pointer and assign it as follows (e.g.):</p>

<pre><code>std::map &lt;std::string, long long &gt;* lpStats = &amp;ioCounterStats;
</code></pre>

<p>It works just fine.  </p>

<p>Could somebody please explain what's going on here.  Thanks!</p>
