C + + writes a non-replicable class

Source: Internet
Author: User

C + + writes a non-replicable class

Flyfish

Effective C + +: clause 06
If you do not want to use a function generated automatically by the compiler, you should explicitly reject it.
Explicitly disallow the use of complier-generated functions you does not want.


Old-fashioned C + + notation

Class Noncopyable{protected:noncopyable () {}~noncopyable () {}private:noncopyable (const noncopyable&); noncopyable& operator= (const noncopyable&);};


the writing of C++11
Class noncopyable{protected:constexpr noncopyable () = default;~noncopyable () = default;noncopyable (const noncopyable& Amp ) = delete;noncopyable& operator= (const noncopyable&) = delete;};


the implementation of boost
Boost does not combine the two methods and also prevents the unconscious ADL (protection from unintended ADL)
ADL (Argument Dependent Lookup)




C + + writes a non-replicable class

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.