What is polymorphism in C + +

Source: Internet
Author: User
What is polymorphism in C + +
  • Introduction
    Polymorphism (polymorphism), Encapsulation (encapsulation) and inheritance (inheritance) are the "three features" of object-oriented thinking, commonly known as " object-oriented kick ", and polymorphism is the most powerful kill in kick, is an object-oriented, the most subtle internal strength, it can be said, do not understand polymorphism does not know what is object-oriented.

  • Defined
    The same action acts on different objects, can have different interpretations, and produces different execution results.
    Simply generalize as "one interface, multiple methods".

  • Category
    (1) Polymorphism at compile time.
    ?? The compile-time polymorphism is implemented by overloading . For non-virtual members, the system compiles, depending on the parameters passed, the type of return, and other information to decide what to do. (Refer to my post, "function overloading in C + +")
    (2) The polymorphism of the runtime.
    ?? Runtime polymorphism means that the operation is not determined according to the actual situation until the system is running. In C + +, run-time polymorphism is implemented through virtual members .

  • Role
    The purpose of polymorphism is to reuse the interface . In other words, regardless of what is passed to the object of that class, functions can be called through the same interface to adapt to the implementation of the respective object.

Copyright NOTICE: This article for csdn bo Master [Applebite] (Http://blog.csdn.net/applebite) original articles, reproduced please indicate the source, infringement must be studied.

What is polymorphism in C + +

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.