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 3498020
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:26:32+00:00 2026-05-18T12:26:32+00:00

Okay, I’ve been reading about rvalues and they seem like a great idea, but

  • 0

Okay, I’ve been reading about rvalues and they seem like a great idea, but something keeps bothering me about them. Particularly the claim that move allows us to steal resources and avoid copying.

I understand that move works and does avoid copying for everything that happens on the stack, but eventually most of the stuff done on the stack yields some value that we want copied into the heap and this is where I don’t think move works.

Assuming that int has a move assignment operator, given the following code:

struct Foo
{
int x;
};

void doIt()
{
Foo* f = new Foo();
f->x = (2 + 4);
}

So in this example, the rvalue resulting from (2+4) can supposedly be moved over to f->x instead of copied. Okay, great. But f and consequently f->x is on the heap and that rvalue is on the stack. It seems impossible to avoid a copy. You cannot simply point f->x to the memory of the rvalue. That rvalue is going to be blown away as soon as doIt ends. A copy seems necessary.

So am I right that a copy will be made?
Or am I wrong?
Or did I completely misunderstand the rvalue concept?

  • 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-18T12:26:33+00:00Added an answer on May 18, 2026 at 12:26 pm

    In this case, it probably would do a copy, but since the object only contains an int, that’s not really much of a problem.

    The times you care are generally when the object contains a pointer to some data that’s allocated on the heap (regardless of where the object itself is allocated). In this case, avoiding allocating a new copy of that data is quite worthwhile (and since it’s on the heap even if the object itself is on the stack, you can move it regardless of where the object itself is located).

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

Sidebar

Related Questions

Okay, so I've known about this for like 600 years now, but I've only
Okay, so I know that using eval() isn't great, but I haven't been able
Okay, I'm reading about Linux kernel development and there are some code snippets using
Okay, I feel a bit foolish for having to ask this but I guess
Okay, this is probably a very basic question; but, I'm just getting back in
Okay, I have GOT to be missing something totally rudimentary here. I have an
Okay, none of the previous questions I have seen with this error seem to
Okay, so this is a long long shot but here it goes... When IE
Okay, I have setup up a handler for a div click but for some
Okay, so the answer to my question might not be the problem but here's

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.