Fourth chapter: Classes and objects

Source: Internet
Author: User

Main content:

1. Object-oriented thinking

Basic features of 2.OOP

3. Concepts and declarations of classes

4. Objects

5. Constructors

6. Destructors

7. Inline function members

8. Copy Constructors

9. Combinations of classes

Class Encapsulation: Allows the consumer to access data (member variables) in a class with specific permissions (private, public, protected) through interfaces (member functions).

Copy constructor: A special constructor whose formal parameters are references to objects of this class.

1. When an object of the class is used to initialize another object of the class, the copy constructor is automatically called to implement copy assignment.

2. If the function's formal parameter is a class object, when the function is called, the argument is assigned to the parameter, and the copy constructor is called automatically by the system.

3. When the return value of a function is a class object, the copy constructor is called automatically by the system.

If the user does not declare a copy constructor for the class, the compiler generates a copy constructor itself. The value of each data member of the object used as the initial value to initialize the corresponding data member of the object that will be established.

Concept of Composition:

The member data in a class is an object of another class.

Forward Reference declaration: (In fact, the name already shows that the role of this technology is a citation statement)

The class is to be declared before it is used. If the class must be referenced before the declaration, a forward reference declaration is required. Only one identifier is referenced for the program, but it is specifically declared elsewhere.

Forward reference declarations cannot: 1. Declaring objects of this class

Use this object in a 2.inline function

Only:

1. The use of declared identifiers cannot involve any details of the class.

Fourth chapter: Classes and objects

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.