Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8986209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:29:47+00:00 2026-06-15T21:29:47+00:00

I just started learning about rvalue references in c++11 by reading this page ,

  • 0

I just started learning about rvalue references in c++11 by reading this page, but I got stuck into the very first page. Here is the code I took from that page.

  int& foo();
  foo() = 42; // ok, foo() is an lvalue
  int* p1 = &foo(); // ok, foo() is an lvalue

  int foobar();
  j = foobar(); // ok, foobar() is an rvalue
  int* p2 = &foobar(); // error, cannot take the address of an rvalue
  1. why is foo() an lvalue? is it because foo() returns int& which is basically an lvalue?
  2. why is foobar() an rvalue? is it because foobar() returns int?
  3. In general, why would you care if a function is an rvalue or not? I think if I read the rest of that article, I’ll get my answer to this.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:29:48+00:00Added an answer on June 15, 2026 at 9:29 pm

    L-Values are locations, R-Values are storable values (i.e., values that can be assigned: namespaces, for instance, are not assignable; thanks to @Maggyero for the edit suggestion).

    So:

    1. since foo() returns a reference(int&), that makes it an lvalue itself.
    2. Correct. foobar() is an rvalue because foobar() returns int.
    3. We don’t care that much if a function is an R-Value or not. What we are getting excited about is R-Value references.

    The article you pointed to is interesting and I had not considered forwarding or the use in factories before. The reason I was excited about R-Value references was the move semantics, such as this:

    BigClass my_function (const int& val, const OtherClass & valb);
    
    BigClass x;
    x = my_function(5, other_class_instance);
    

    In that example, x is destroyed, then the return of my_function is copied into x with a copy constructor. To get around that historically, you would write:

    void my_function (BigClass *ret, const int& val, const OtherClass & valb);
    
    BigClass x;
    my_function(&x, 5, other_class_instance);
    

    which means that now my_function has side effects, plus it isn’t as plain to read. Now, with C++11, we can instead write:

    BigClass & my_function (const int& val, const OtherClass & valb);
    
    BigClass x;
    x = my_function(5, other_class_instance);
    

    And have it operate as efficiently as the second example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Very confused over this. I've just started learning about pointers and have now decided
I've just started learning about hash tables and I understand how to insert but
I just started learning about Lucene and I get how it can be very
I've only started learning Java about 3 months ago and this is my first
I just started learning about pointers in C++, and I'm not very sure on
I just started learning opengl and writing a first person shooter but I'm getting
I've just started learning about parsing, and I wrote this simple parser in Haskell
I'm using $_get for a simple page redirection. I've only just started learning about
I've just started learning about thread safety. This is making me code a lot
I just recently have started learning about the wonders of **kwargs but I've hit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.