What is polymorphism, what is it for, and how is it used?

前端 未结 28 2726
南笙
南笙 2020-11-21 07:08

What is polymorphism, what is it for, and how is it used?

28条回答
  •  北恋
    北恋 (楼主)
    2020-11-21 07:42

    I've provided a high-level overview of polymorphism for another question:

    Polymorphism in c++

    Hope it helps. An extract...

    ...it helps to start from a simple test for it and definition of [polymorphism]. Consider the code:

    Type1 x;
    Type2 y;
    
    f(x);
    f(y);
    

    Here, f() is to perform some operation and is being given the values x and y as inputs. To be polymorphic, f() must be able to operate with values of at least two distinct types (e.g. int and double), finding and executing type-appropriate code.

    ( continued at Polymorphism in c++ )

提交回复
热议问题