Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the inherited characteristics in C++?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "what are the characteristics of inheritance in C++". In daily operation, I believe that many people have doubts about the characteristics inherited in C++. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "what are the characteristics of inheritance in C++?" Next, please follow the editor to study!

# # inheritance Features

The subclass has all the properties and methods of the parent class (except constructors and destructors).

A subclass can have properties and methods that the parent class does not have.

Inheritance syntax class derived class name: inheritance method base class name 1, inheritance method base class name 2, inheritance method base class name n {derived class member declaration;}; inherited access control

Public inheritance: the member of the parent class maintains the original access level in the subclass (the subclass can access public and protected).

Private inheritance: members of the parent class become private members in the subclass (although the members of the parent class are private decorated in the subclass, the public and protected of the parent class are allowed to be accessed because they are inherited and changed to private).

Protected inheritance

Public members in the parent class become protected-level.

The protected member in the parent class is still at the protected level.

The private member in the parent class is still at the private level.

Note: private members in the parent class still exist in the subclass, but cannot be accessed. No matter how you inherit the parent class, the subclass cannot directly use the private members of the parent class.

Constructor derived class name in inheritance:: derived class name (parameter summary): base class name 1 (parameter table 1), base class name (parameter name 2). Base class name n (parameter name n), embedded sub-object 1 (parameter table 1), embedded sub-object 2 (parameter table 2). Embedded sub-object n (parameter table n) {initialization statement for new members of derived classes;}

The    constructor is for the data in the initial class, and for the derived class, it does not inherit the constructor of the base class, so in order to complete the initialization of the derived class data, it is necessary to define the constructor in the derived class. The constructor of the derived class needs to initialize the data members in the base class in addition to the new data members in the derived class.

Class student {public: void display () {cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

  • Building hadoop Cluster (2) High availability of YARN

    [root@hadoop01 ~] # vim / usr/local/hadoop-2.7.1/etc/hadoop/yarn-site.xml

    © 2024 shulou.com SLNews company. All rights reserved.

    12
    Report