Polymorphism in C ++ Learning (several characteristics of polymorphism)

Source: Internet
Author: User

Polymorphism in C ++ Learning (several characteristics of polymorphism)

1. the virtual function feature can be inherited. When the function defined in the subclass is the same as the virtual function declared in the parent class (the same parameter with the same name returns the same value), this function is also a virtual function; when the parent class Pointer Points to the subclass object, when the pointer calls this function with the same name, it will call the subclass function, which is a polymorphism;

2. The virtual destructor aims to avoid Memory leakage when the parent class pointer is used to release subclass objects;

3. The implementation of polymorphism in c ++ is implemented through the virtual function table;

4. Each class has only one virtual function table, and all the objects in this class share the same virtual function table;

5. The pointers in the two virtual function tables may point to the same function (for details, see the blog on the virtual function table );

6. When the class only contains virtual destructor, this class will also generate a virtual function table;

7. polymorphism-specific syntax refers to the use of a parent class pointer to point to a subclass object, and this pointer can be used to call the subclass method;

8. inheritance is the basis for producing polymorphism, and there is no polymorphism without inheritance.

9. The core of polymorphism syntax is the virtual keyword. You must use virtual to establish polymorphism between multiple classes.

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.