Posted on April 28th, 2007 at 14:36 by fr3@K
I recently came across a mistake in The rvalue Reference Proposal published in Informit’s C++ Reference Guide.
Let’s first take a look at the example code snips in section Overloading and Overload Resolution. Please note the last two lines, where the error lies:
void f(const A& a); // #1 lvalue reference void f(A&& a); // #2 rvalue reference
struct A {}; A f(); const A cf(); A a; const A ca; f(a); // calls #1 f(ca); // calls #1 f(source()); // calls #2 f(const_source()); // calls #1
With this example alone, I was unable to tell what source() or const_source() was. After some Googling, I dug up another example in a paper published by the C++ Standards Committee, and it closely resembles the example from Informit:
void foo(const A& t); // #1 void foo(A&& t); // #2
struct A {}; A source(); const A const_source(); ... A a; const A ca; foo(a); // binds to #1 foo(ca); // binds to #1 foo(source()); // binds to #2 foo(const_source()); // binds to #1
Alright, this example from C++ Standard Committee’s paper made sense. The source() and const_source() were two generator functions (functions those return values but take no argument). Their return values were used as arguments to two of the overloaded foo()s.
![]() |
|
| Previous Post « Compiz, Not So Cool « |
Next Post » 週三公司早餐報名 » |








void foo(A&& t); // #2
What is A&&? You cannot have a reference to a reference. It is disallowed in C++.
Adrian
Comment by Adrian — May 2, 2007 @ 1:12