473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Get lvalue through rvalue

Hello everyone,
I do not know how in the following code, rvalue -- return of X(),
could result in a lvalue finally and binded to a non-const reference
input parameter of function f.

Any ideas?

Expand|Select|Wrap|Line Numbers
  1. struct X {
  2.  
  3.  
  4. };
  5.  
  6. void f (X& x) {}
  7.  
  8. int main()
  9. {
  10. f (X() = X());
  11.  
  12. return 0;
  13. }
  14.  

thanks in advance,
George
Dec 17 '07 #1
1 1326
George2 wrote:
I do not know how in the following code, rvalue -- return of X(),
could result in a lvalue finally and binded to a non-const reference
input parameter of function f.
You're confusing the return type of 'X()' and the full expression
that you can see inside the parentheses where 'f' is called.
>
Any ideas?

Expand|Select|Wrap|Line Numbers
  1. struct X {
  2. };
  3. void f (X& x) {}
  4. int main()
  5. {
  6. f (X() = X());
  7. return 0;
  8. }
  9.  
The trick here is based on the fact that every temporary of a class
type is a separate object, for which you can call member functions.
The operator= is a member function. What is its usual signature?
Rewrite the expression

f( X() = X() )

in terms of member function calls, and you will hopefully see how
an r-value can be turned into an l-value.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Dec 17 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Hongzheng Wang | last post by:
In K&R, they said: An object is a named region of storage; an lvalue is an expression refer to an object. How about these concept in C++? `The C++ Programming Language' has a similar...
9
by: Steven T. Hatton | last post by:
This is from the draft of the previous version of the Standard: http://www.kuzbass.ru:8086/docs/isocpp/expr.html 2- A literal is a primary expression. Its type depends on its form...
24
by: Romeo Colacitti | last post by:
Hi, Does anyone here have a strong understanding for the meanings of the terms "lvalue" and "rvalue" as it pertains to C, objects, and different contexts? If so please share. I've been...
9
by: Kavya | last post by:
These were the questions asked to me by my friend 1. Operator which may require an lvalue operand, yet yield an rvalue. 2. Operator which may require an rvalue operand, yet yield an lvalue. ...
14
by: nobrow | last post by:
Yes I know what lvalue means, but what I want to ask you guys about is what are all valid lvalues ... a *a a *(a + 1) .... What else?
6
by: Lighter | last post by:
How to read "The lvalue-to-rvalue, array-to-pointer, and function-to- pointer standard conversionsare not applied to the left expressions"? In 5.18 Comma operator of the C++ standard, there is a...
6
by: Yarco | last post by:
I've alway thought lvalue means Left Value and rvalue means Right Value before i've read someone's article. It is said "lvalue = location value" and "rvalue = read value". Which one is right, then?
9
by: usao | last post by:
Does anyone have an example of how to create a class which describes and array, such that I can use the subscript operator on both the left and right side of an assignment statement? This is as...
2
by: Chad | last post by:
The following question actually stems from an old Chris Torek post. And I quote from the following old CLC url ...
2
by: Chad | last post by:
I have the folllowing #include <stdio.h> int main(void) { int x = 1, y = 2; int *ip; ip = &x;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.