C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

R-value and function overload selection

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Joshua Lehrer
Guest





PostPosted: Sat Jun 03, 2006 3:43 am    Post subject: R-value and function overload selection Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.