C++ Object-Oriented Overview | Student Class

C++ object-oriented overview

Before this section, Kobayashi talked about C++ process-oriented. After this section, he will start to talk about object-oriented. Readers will find that the C language they have learned has changed drastically.

What is an object

Anything in the objective world can be regarded as an object, which can be large or small, and is the basic unit of the system.

Any object has two elements

  1. Attributes
  2. behavior

An object is often composed of a set of attributes and a set of behaviors. Anything that has both attributes and behaviors can be used as an object.

In C++, each object is composed of two parts: data and function. An object is often composed of a set of attributes and a set of behaviors. Anything with attributes and behaviors can be used as objects.

Three characteristics of object-oriented

  1. Package
  2. inherit
  3. Polymorphism

Encapsulation refers to two aspects: one is to encapsulate relevant data and operation codes in an object to form a basic unit, and each object is relatively independent and does not interfere with each other; the other is to conceal certain parts of the object from the outside, namely Conceal its internal details, leaving only a small number of interfaces to communicate with the outside world and receive outside news.

If you have established a class named A in software development, and you want to create another class named B", the latter is basically the same as the former, except that some attributes and behaviors are added to the former. Just add some new content on the basis of Class A. This is the inheritance in object-oriented programming.

In C++, the so-called polymorphism refers to: related different classes produced by inheritance, whose objects will respond differently to the same message, polymorphism is an important feature of object-oriented programming, which can increase the program's flexibility.

Case: C++ defines the student class.

class Student
{
    
    
  void print_Student()
  {
    
    
    cout<<"我是学生类"<<endl; 
  }
}

C++ object-oriented overview
More cases can go to the public account: C language entry to proficient

Guess you like

Origin blog.csdn.net/weixin_48669767/article/details/112548441