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

  • SEARCH
  • Home
  • 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 6363609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:03:33+00:00 2026-05-25T00:03:33+00:00

I have 3 questions: Can I bind a lvalue directly to a rvalue reference?

  • 0

I have 3 questions:

  1. Can I bind a lvalue directly to a rvalue reference?

  2. What happens to the object that being std::move()?

  3. What’s the difference between std::move and std::forward?

struct myStr{
    int m_i;
};

void foo(myStr&& rs) { }

myStr rValueGene()
{
    return myStr();
}

int main() 
{
    myStr mS= {1};
    foo(rValueGene()); //ok passing in modifiable rvalue to rvalue reference

    // To Question 1:
    //below initilize rvalue reference with modifiable lvalue, should be ok
    //but VS2010 gives a compile error: error C2440: 'initializing' : cannot convert from    'myStr' to 'myStr &&' 
    //Is this correct ?
    myStr&& rvalueRef = mS;

    //by using std::move it seems ok, is this the standard way of doing this 
    //to pass a lvalue to rvalue reference
    //myStr&& rvalueRef = std::move(mS);

    // To Question 2:    
    //also what happens to mS object after std::move ?
    //destroyed , undefined ?
}
  • 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-05-25T00:03:34+00:00Added an answer on May 25, 2026 at 12:03 am

    1>Can I bind a lvalue directly to a rvalue reference ?

    Not without an explicit cast (ie: std::move).

    2>What happens to the object that being std::move() ?

    Nothing until it is actually moved. All std::move does is return an r-value reference to what you gave it. The actual moving happens in the move constructor/assignment of the type in question.

    3>What’s the difference between std::move and std::forward ?

    std::move is for moving; std::forward is for forwarding. That sounds glib, but that’s the idea. If you are intending for an object to be moved, then you use std::move. If you are intending for an object to be forwarded, you use std::forward.

    Forwarding uses specialized semantics that allow conversions between types of references, so that the reference natures are preserved between calls. The specifics of all of this are very… technical.

    std::move always returns a &&. If you give it an l-value reference, it returns an r-value reference. If you give it a value type, it returns an r-value reference to that value. And so forth.

    std::forward does not always return a &&. Syntactically, std::forward is just doing a static_cast<T&&>. However, because of specialized syntax around casting to && types, this cast does not always return a &&. Yes, that’s weird, but it solves the forwarding problem, so nobody cares. That’s why it’s contained in std::forward, rather than having to explicitly do the static_cast yourself.

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

Sidebar

Related Questions

I have javascript string variable with var sttr=We prefer questions that can be answered
I have 2 questions: 1- We all know that can create an array list
I am new to JNI. And have a few questions : Can JNI handle
I have two questions: 1) How can I make an array which points to
I have questions about System.Threading.ThreadStart Class : where can I find its specifications (
I have some questions which are as follows: How can I use the JSP
I have several questions regarding filenames and the iPod Library. I understand I can
I feel like GUID/UUID questions have been done to death here, but I can't
Related to https://stackoverflow.com/questions/139944/where-can-one-find-free-software-icons-images I have a need for free weather-related icons. Specifically, I need
I have been repeatedly asked the following questions in many interviews.... But still can't

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.