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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:20:25+00:00 2026-06-14T18:20:25+00:00

Ignoring the sanity of doing what I’m describing, does using the std::move() function improve

  • 0

Ignoring the sanity of doing what I’m describing, does using the std::move() function improve construction time when used to pass an argument to a base constructor?

struct Bar {
    Bar(std::string);

    std::string _s;
}

struct Foo : public Bar {
    Foo(std::string);
}


struct Bar(std::string bs) : _s(std::move(bs)) {
    // 1
}

struct Foo(std::string fs) : Bar(std::move(fs)) {
    // 2
}

So in this example, does the move() used in Foo‘s constructor prevent an additional copy of the string being made?

And for clarification, does this design mean no attempt should be made to use bs and fs at points // 1 and // 2, but using _s would be safe in both places?

  • 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-14T18:20:27+00:00Added an answer on June 14, 2026 at 6:20 pm

    To find out, I recoded your example with a fake String class like so:

    #include <iostream>
    
    struct String
    {
        String() {}
        String(const String&) {std::cout << "String(const String&)\n";}
        String& operator=(const String&)
            {std::cout << "String& operator=(const String&)\n"; return *this;}
        String(String&&) {std::cout << "String(String&&)\n";}
        String& operator=(String&&)
            {std::cout << "String& operator=(String&&)\n"; return *this;}
    };
    
    struct Bar {
        Bar(String);
    
        String _s;
    };
    
    struct Foo : public Bar {
        Foo(String);
    };
    
    
    Bar::Bar(String bs) : _s(std::move(bs)) {
        // 1
    }
    
    Foo::Foo(String fs) : Bar(std::move(fs)) {
        // 2
    }
    int main()
    {
        Foo f{String()};
    }
    

    For me this prints out:

    String(String&&)
    String(String&&)
    

    But if I remove this std::move from the Foo constructor the printout changes to:

    String(const String&)
    String(String&&)
    

    So assuming a String(String&&) is faster than a String(const String&), the former is faster. Otherwise, not.

    And for clarification, does this design mean no attempt should be made
    to use bs and fs at points // 1 and // 2, but using _s would be safe
    in both places?

    Correct.

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

Sidebar

Related Questions

Google's feed loader appears to be ignoring attributes when converting to JSON. I'm using
Why does this empty the text immediately (ignoring delay)? $('#error_box_text').html('error text').delay(5000).html('') # jQuery 1.4
When using Xcode analysis (product>analyze) is there a way of ignoring any errors in
Is there an easy way of using the RegularExpressionValidator control while ignoring white space?
Is there a function in Python to split a string without ignoring the spaces
Does anyone know away of ignoring selected tests when the network is unavailable. Something
Internet Explorer seems to be ignoring this ajax function call (below) but it works
I want to compare two string ignoring real time factors like date and time
Is there a way to compare two dates (which include time) ignoring the time?
Ignoring price for the moment, would using Unity for a 2D game be better

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.