C + + polymorphism

Source: Internet
Author: User

Polymorphism definition : Different classes that are generated by inheritance, send the same message to their objects, and different objects receive a different behavior (that is, methods).
A member function declared in a base class as vitual and redefined in one or more derived classes.The usage format is: vitual function return type function name (parameter table) {function Body};

To achieve polymorphism, access the overridden member function with the same name in the derived class by pointing to the base class pointer or reference of the derived class.

Virtual Functions : You can let member function operations generalize, when a base class pointer points to an object of a different derived class, the base class pointer calls its virtual member function, and it calls its member function that actually points to the object. Instead of the member function defined in the base class (as long as the derived class overrides the member function). If it is not a virtual function, it will call the function defined in the base class, regardless of which derived class object the base class pointer points to.

C + + polymorphism

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.