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