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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:28:35+00:00 2026-06-06T14:28:35+00:00

While I’m reading boost/shared_ptr.hpp, i saw this code: // generated copy constructor, destructor are

  • 0

While I’m reading boost/shared_ptr.hpp, i saw this code:

//  generated copy constructor, destructor are fine...

#if defined( BOOST_HAS_RVALUE_REFS )

// ... except in C++0x, move disables the implicit copy

shared_ptr( shared_ptr const & r ): px( r.px ), pn( r.pn ) // never throws
{
}

#endif

What does the comment “generated copy constructor, destructor are fine except in C++11, move disables the implicit copy” mean here? Shall we always write the copy ctor ourselves to prevent this situation in C++11?

  • 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-06T14:28:38+00:00Added an answer on June 6, 2026 at 2:28 pm

    I’ve upvoted ildjarn’s answer because I found it both accurate and humorous. 🙂

    I’m providing an alternate answer because I’m assuming because of the title of the question that the OP might want to know why the standard says so.

    background

    C++ has implicitly generated copy members because if it didn’t, it would’ve been still-born in 1985 because it was so incompatible with C. And in that case we wouldn’t be having this conversation today because C++ wouldn’t exist.

    That being said, implicitly generated copy members are akin to a "deal with the devil". C++ couldn’t have been born without them. But they are evil in that they silently generate incorrect code in a significant number of instances. The C++ committee isn’t stupid, they know this.

    C++11

    Now that C++ has been born, and has evolved into a successful grownup, the committee would just love to say: we’re not doing implicitly generated copy members any more. They are too dangerous. If you want an implicitly generated copy member you have to opt-in to that decision (as opposed to opt-out of it). However considering the amount of existing C++ code that would break if this was done, that would be tantamount to suicide. There is a huge backwards compatibility concern that is quite justified.

    So the committee reached a compromise position: If you declare move members (which legacy C++ code can’t do), then we’re going to assume that the default copy members are likely to do the wrong thing. Opt-in (with =default) if you want them. Or write them yourself. Otherwise they are implicitly deleted. Our experience to-date in a world with move-only types indicates that this default position is actually quite commonly what is desired (e.g. unique_ptr, ofstream, future, etc.). And the expense of opting-in is actually quite small with = default.

    Looking Forward

    The committee would love to even say: If you’ve written a destructor, it is likely that the implicit copy members are incorrect, so we will delete them. This is the C++98/03 "rule of three". However even that would break lots of code. However the committee has said in C++11 that if you provide a user-declared destructor, the implicit generation of copy members is deprecated.1, 2 That means that this feature could be removed in a future standard. And that any day now your compiler might start issuing "deprecated warnings" in this situation (the standard can not specify warnings).

    Conclusion

    So be forewarned: C++ has grown up and matured over the decades. And that means that your father’s C++ may need migrating to deal with your child’s C++. It is a slow, gradual process so that you don’t throw up your hands and just port to another language. But it is change, even if slow.


    1 http://eel.is/c++draft/class.mem#class.copy.ctor-6.sentence-3

    2 http://eel.is/c++draft/class.mem#class.copy.assign-2.sentence-3

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

Sidebar

Related Questions

While reading this class BitmapFactory I noticed that almost all methods inside are static.
While executing this below Dojo code the call back mehod is calling the onFailure.
While using boost::threads I have come across this interruption problem. When I do a
While compiling a while loop without a body, I saw this message: warning: suggest
While reading http://en.wikipedia.org/wiki/C_preprocessor#Multiple_evaluation_of_side_effects , I came across this example: \#define max(a,b) \ ({ typeof
While browsing the source code of the Scala API, I met this package definition
While debugging and keep pressing F5, if the source code does not exist, eclipse
while looking at some code I stumbled onto: throw /*-->*/new std::exception (//... and I
While refactoring my code base I found a piece of code which I'd like
while($c=fgets(STDIN)){ if($c===PHP_EOL){ continue; } else { echo $c; } } When the above code

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.