Non-lvalues as function parameters in C++
<p>I'm reading Accelerated C++ and in Chapter 4 they bring up the concept of lvalues. There's an example of something that <em>shouldn't</em> work, but after trying it myself I found that it does indeed work.</p>

<p>Specifically they state that, given these functions:</p>

<pre><code>// return an empty vector
vector&lt;double&gt; emptyvec()
{
  vector&lt;double&gt; v;
  return v;
}

// read things from an input stream into a vector&lt;double&gt;
// (I'm leaving out the function body here because it's irrelevant)
istream &amp;read_things(istream&amp; in, vector&lt;double&gt;&amp; hw);
</code></pre>

<p>This should not be allowed:</p>

<pre><code>read_stuff( cin, emptyvec() );
</code></pre>

<p>Because emptyvec() is an expression and returns a temporary object (a <em>non-lvalue</em> as they called it in the book). However, this not only compiles but actually runs (Windows 7/VisualStudio 2010).</p>

<p>So, what's going on? Was this just a bad example on the authors' part, or is there something else happening that I don't understand.</p>

<p>Thanks.</p>
