The second leading edge of C + + (ii)-Classes and objects (upper)

Source: Internet
Author: User

1. Composition of classes: Data and functions

Public: can be accessed by an object of the class outside the class

Private: Accessible only by member functions within a class

Protected: Can be accessed by a member function of this class, or by a member function of a derived class of this class

Access keyword: Private is the default keyword

!! It is not possible to assign an initial value to a data member in a class declaration, that is, to initialize it, and to assign an initial value to the data member only after the class's object definition

2. member functions

There are three member functions based on access rights, where private member functions can only be accessed by other member functions in this class, and public member functions may be accessed by objects of that class outside the class

In addition, it can be divided into ordinary member functions and inline member functions .

Inline member functions are also divided into implicit declarations and explicit declarations

This detail will not knock up, rectification 52 pages

3. Definition and use of objects

  1. Defining objects directly

2. Define a pointer object that has no name, called a nameless object, but that object has an address that is stored in the pointer variable

4. Class scope and access properties for classes

Object Assignment Statement , the assignment between C + + two objects of the same type is implemented by overloading the operator

Simply assign a value to the data member in the object and not assign a value to the member function

Assigning a value using = when there is a pointer in the class can produce an error

5. Constructors

Function: Because the class itself does not allow assignment initialization at the time of definition, it produces a function that is specifically used to initialize the assignment, the constructor

Characteristics:

1. No return value

2. Same name as Class

3. Allow custom parameters

4. Special member functions

5. Automatically execute when an object is created

6. Initialize the member list (depending on the constructor)

Primarily used to initialize a type member that is not allowed to be assigned with an assignment statement

  For example, a data member that references and the const modifier decorates

7. Constructors with default parameters

Balabala no need to explain.

The second leading edge of C + + (ii)-Classes and objects (upper)

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.