C ++ Summary-object-oriented

Source: Internet
Author: User

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

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.