Stroustrup on the new features of C + + 11

Source: Internet
Author: User
Tags deprecated

Reprinted from http://www.stroustrup.com/C++11FAQ.html

For personal reference only, for collection

Control of Defaults:move and copyby default, A-class has 5 operations:
    • Copy Assignment
    • Copy constructor
    • Move Assignment
    • Move constructor
    • destructor
If You declare any of those to must consider all and explicitly define or default the ones you want. Think of copying, moving, and destruction as closely related operations, rather than individual operations that you can FR eely mix and match-you can specify arbitrary combinations, but only a few combinations make sense semantically.

If any move, copy, or destructor are explicitly specified (declared, defined, =default, or =delete) by the user, no move is Generated by default. If any move, copy, or destructor are explicitly specified (declared, defined, =default, or =delete) by the user, any undecl Ared copy operations is generated by default, but it is deprecated and so don ' t rely on that. For example:

Disallow copying
This implicitly also disallows moving of X1S. Copy initialization is allowed, but deprecated.
This implicitly also disallows moving of X2S. Copy initialization is allowed, but deprecated.
Disallow Moving
This implicitly also disallows copying of X3S.
Disallow Destruction
This implicitly also disallows moving of X4S. Copying is allowed, but deprecated.

I strongly recommend so if you declare one of the these five function, you explicitly declare all. For example:

user-defined destructor:no implicit copy or move   transfer ownershiptransfer Ownership  /c5>no copy handle& operator= (const handle&) = delete;  ...

See Also

    • The C + + Draft section???
    • [n2326==07-0186] Lawrence crowl:defaulted and Deleted Functions.
    • [n3174=100164] B. Stroustrup:to move or not to move. An analysis of problems related to generated copy and move operations. Approved.

Stroustrup on the new features of C + + 11

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.