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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:40:54+00:00 2026-05-27T00:40:54+00:00

Sorry if this has been asked before, but as I understand it, in C++11,

  • 0

Sorry if this has been asked before, but as I understand it, in C++11, std::vector has a move constructor so that copies cost hardly anything in certain situations, like returning one by value. However, if I have a class like this, with a vector as a member variable:

class MyClass {
public:
    MyClass() { }
    MyClass(const MyClass& rhs) { }

    // other interfaces

private:
    std::vector<int> myvec;

    // implementation
};

And have a function which returns one of these by value, such as

MyClass somefunc() {
    MyClass mc;
    // fill mc.myvec with thousands (maybe even millions) of ints
    return mc;
}

Will the move constructor of mc.myvec be called and the move constructor of std::vector taken advantage of even though MyClass itself doesn’t know anything about move constructors? Or will the copy constructor of vector be called and all those thousands (maybe even millions) of ints have to be copied one by one?

  • 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-27T00:40:55+00:00Added an answer on May 27, 2026 at 12:40 am

    If you don’t write any explicit copy or move constructors or any copy or move assignment operators or a destructor, then the default-provided move-constructor moves elements one-by-one. For details, see 12.8.9.

    Since you define your own copy constructor, you will not get a move constructor by default. Either define one (perhaps = default), or get rid of the explicit copy constructor.

    Well-composed classes shouldn’t usually need any custom Big Five, and instead rely on members providing them and use the default version.

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

Sidebar

Related Questions

Sorry if this has been asked before, but I'm wondering what the best memory
Sorry if this has been asked before, I did check but couldn't find anything...
sorry if this questions is overly basic or has been asked before but I
I'm sorry if this has been asked before, but I'm in kind of a
I'm sorry if this questions has been asked before, but I couldn't find an
Sorry if this has been asked before but I've tried searching and can't find
sorry if this question has been asked before, I searched but wasn't sure on
Sorry I know this question has probably been asked before, but do you know
Sorry if this has been asked before, but I couldn't find a solution to
I'm sorry if this question has been asked before, but I can't seem to

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.