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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:56:50+00:00 2026-05-31T15:56:50+00:00

I saw this here: Move Constructor calling base-class Move Constructor Could someone explain: the

  • 0

I saw this here:
Move Constructor calling base-class Move Constructor

Could someone explain:

  1. the difference between std::move and std::forward, preferably with some code examples?
  2. How to think about it easily, and when to use which
  • 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-31T15:56:51+00:00Added an answer on May 31, 2026 at 3:56 pm

    std::move takes an object and allows you to treat it as a temporary (an rvalue). Although it isn’t a semantic requirement, typically a function accepting a reference to an rvalue will invalidate it. When you see std::move, it indicates that the value of the object should not be used afterwards, but you can still assign a new value and continue using it.

    std::forward has a single use case: to cast a templated function parameter (inside the function) to the value category (lvalue or rvalue) the caller used to pass it. This allows rvalue arguments to be passed on as rvalues, and lvalues to be passed on as lvalues, a scheme called “perfect forwarding.”

    To illustrate:

    void overloaded( int const &arg ) { std::cout << "by lvalue\n"; }
    void overloaded( int && arg ) { std::cout << "by rvalue\n"; }
    
    template< typename t >
    /* "t &&" with "t" being template param is special, and  adjusts "t" to be
       (for example) "int &" or non-ref "int" so std::forward knows what to do. */
    void forwarding( t && arg ) {
        std::cout << "via std::forward: ";
        overloaded( std::forward< t >( arg ) );
        std::cout << "via std::move: ";
        overloaded( std::move( arg ) ); // conceptually this would invalidate arg
        std::cout << "by simple passing: ";
        overloaded( arg );
    }
    
    int main() {
        std::cout << "initial caller passes rvalue:\n";
        forwarding( 5 );
        std::cout << "initial caller passes lvalue:\n";
        int x = 5;
        forwarding( x );
    }
    

    As Howard mentions, there are also similarities as both these functions simply cast to reference type. But outside these specific use cases (which cover 99.9% of the usefulness of rvalue reference casts), you should use static_cast directly and write a good explanation of what you’re doing.

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

Sidebar

Related Questions

Here is one more newbie question: require 'tasks/rails' I saw this line in Rakefile
const static int foo = 42; I saw this in some code here on
I saw this signature on the ListView class: public ListView..::.ListViewItemCollection Items { get; }
So I saw this post here and read it and it seems like bulk
I saw this link here: How to detect Facebook share success? with Javascript But
I saw this in someone's code. What does it mean? def __enter__(self): return self
I just saw this here #include <stdio.h> int main(int argc, char *argv[printf(Hello, world!\n)]) {}
I saw this post here , he explains well howto show a highlighted result,
I've been interested in this demo: http://jakearchibald.com/scratch/alphavid/ I also saw this question on here:
I'm making a javascript/canvas game and I saw this example on CSS Tricks. 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.