C ++ is often regarded as "C with Class". In fact, C ++ introduces a complete object-oriented idea and adds many basic structures to support this idea.
Class and struct
Classes and struct in C ++ are very similar.
C ++ inheritance
C ++ does not have the interface keyword, but has the interface idea. In fact, a pure virtual function is an interface. Because there is no interface concept, C ++ does not implement (implements). It has only inheritance. Unlike Java, C ++ supports multi-inheritance. C ++ can be inherited in two ways: single inheritance and multi-inheritance. For single inheritance, the derived class has only one base class. For multi-inheritance, A derived class is generally derived from multiple base classes. The format is:
Single inheritance format: class derived class name: Inheritance Method Base class Name
Multi-inheritance format: class derived class name: Inheritance Method 1 base class name 1 ,......, Inheritance Method n base class name n
Apart from single inheritance and multi-inheritance, C ++ inherits public inheritance, protected inheritance, and private inheritance. See the following table:
Access attribute of a derived class member
Access attributes of base class members
Inheritance Method
Public
Protected
Private
Public
Public
Protected
Private
Protected
Protected
Protected
Private
Private
Hide in a derived class
Hide in a derived class
Hide in a derived class
In addition, the concept of virtual inheritance exists in C ++:
Class derived class name: base class name in virtual inheritance mode