C ++ primer Study Notes-class

Source: Internet
Author: User
Classes are often referred to as user-defined types (UDT) ----------------------------------- Class Definition 1 has two parts: Class headers, which are composed of the keyword class and its class names. Class body, surrounded by a pair of curly braces. The class definition must be followed by a semicolon or a column declaration. Example: Class Screen {/*... */}; Class Screen {/*... */} myscreen, yourscreen; 2 data members other than static data members cannot be explicitly initialized in the class body, for example, class first {int Memi = 0; // error double memd = 0.0; // error }; 3. A friend Declaration starts with the keyword "friend". It can only appear in the declaration of the class. Because friends are not members of the class that authorizes the friendship, they are not declared in the Public Private and Protected Areas in the class body. in this case, we choose to organize all the membership declarations after the Class header. 4 because only when the class body of a class is complete can it be considered as being defined, so a class cannot have its own A data member of the type. However, when the Class header of a class is viewed, it is regarded as declared. Therefore, a class can use a pointer to its own type or reference as a data member. 5. Although each class object has its own class data member copy, only one copy of each class member function is available, such as screen myscreen, groupscreen, and myscreen. home (); groupscreen. home (); when the home () function is called for the object myscreen, the member _ cursor accessed in Home () is the data member of the object myscreen. When the object groupscreen is called home () when the data member _ cursor references the data member of the object groupscreen, the two call the same function home () how can a member function reference data members of two different class objects? This support is implemented through the this pointer. 6. Only a member function declared as const can be called by a const class object. The keyword const is placed between the parameter table of the member function and the function body. For a const member function defined outside the class body, we must specify the keyword const.7 in its definition and description. Constructor and destructor are two exceptions. Even if the const and const functions are not const member functions, they can be called. When the const class object is initialized, the Class Object the const class object is considered as const.8 13.36 during the time from the time when the const class object is constructed to the time when the const.8 class object is called. mutable data member?

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.