 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Joshua Lehrer Guest
|
Posted: Sat Jun 03, 2006 3:43 am Post subject: R-value and function overload selection |
|
|
Please consider the following sample code:
struct T {};
void func(const T&); //#1
void func(T&); //#2
T foo();
void test() {
func(foo());
}
Our old compiler compiled this code just fine, selecting func #1 from
the overload set.
Our new version of the same compiler fails to compile the code. It
complains that the initial value of a reference to non-const must be an
lvalue. As foo() is returning an rvalue, not an lvalue, it can't call
#2. But why can't it call #1?
I assume the new compiler is correct, but I don't understand why. Can
anyone explain further and perhaps reference The Holy Standard?
Thanks,
joshua lehrer
http://www.lehrerfamily.com/
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|