Valid C ++ clause 5 and valid clause 5

Source: Internet
Author: User

Valid C ++ clause 5 and valid clause 5
Understand which functions are written and called by C ++ by default

This section contains two knowledge points.

For a class
1. If no constructor exists in the class, the compiler declares a default constructor for the class.
2. If the class has no destructor, copy constructor, or copy assignment operator, the class declares the three functions.
3. the compiler generates the destructor, copy constructor, and copy assignment operators only. The declaration and generation are two different codes.

The following code:

// Defined classclass Empty {}; // classclass Empty {public: Empty () {} Empty (const Empty & rhs) declared by the compiler) {} Empty & operator = (const Empty & rhs ){}~ Empty (){}};

If data of the reference type or const type exists in the class. The compiler rejects the automatic generation of the copy assignment operator function. Unless you define
The following code:

// For this class, the compiler will not automatically generate the copy assignment template <typename T> class NamedObject {public: NamedObject (const char * name, const T & value); NamedObject (const std:: string & name, const T & value); private: std: string & nameValue; const T objectValue ;};

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: 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.