C ++ Object-Oriented Technology

Source: Internet
Author: User
1. What are the basic concepts of object-oriented technology?
Objects, classes, and inheritance.
2. virtual functions and Polymorphism
A virtual function is a member function that can be redefined by its subclass. The sub-class redefinition of the parent class virtual function is called override ).
Polymorphism allows you to set a parent object to be equal to one or more sub-objects. After a value is assigned, the parent object can operate in different ways based on the sub-objects assigned to it. To put it simply, a pointer of the subclass type can be assigned to a pointer of the parent class. Polymorphism is implemented through virtual functions in C ++.
3. What is the role of polymorphism?
Encapsulation can hide implementation details, so that Code Modularization; inheritance can extend existing code modules (classes) for code reuse. Polymorphism aims to achieve another purpose-interface reuse!
4. Interface
C ++ does not actually have the interface keyword. It is implemented by pure virtual functions of abstract classes.
5. About classes
The private internal representation of a class is called an encapsulation, and a common part of the class is called a class interface ).
Total members: Program Can be accessed anywhere. Classes that implement information hiding restrict their public members to member functions. To access a member function, you must define a class object.
Private Members: they can only be accessed by Friends of member functions and classes. classes that hide information declare their data members as private.
Protected members: For a derived class, just like public, Other programs behave like private . In non-inherited classes, the protected and private controllers are not different.
6. shared inheritance, private inheritance, and protection inheritance
In public inheritance, the object of the derived class can access the public members in the base class, and the member functions of the derived class can access the public members and protected members in the base class.
In private inheritance, the base class members are invisible to all the members of the base class for the derived class objects.
For a derived class, the public and protected members of the base class are visible and can be accessed using member functions.
Private inheritance means that the member of the base class cannot be inherited by the later class.
When protecting inheritance, both the common and protected members of the base class serve as the protected members of the derived class, which means they can be accessed by "classes derived from the class later, but cannot be accessed outside the hierarchy.
7. Inheritance of virtual functions and virtual inheritance
These two concepts are confusing.
The inheritance of virtual functions is actually virtual functions. However, virtual functions must be used in inheritance. Otherwise, they do not need to exist. It refers to a dynamic binding process.
Virtual inheritance is a special concept in Multi-inheritance. It refers to retaining only the parent class of the parent class in the subclass ...... So that the subclass contains the same member of the parent class multiple times.
Related Article

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.