C和我考试中的多态性

前端之家收集整理的这篇文章主要介绍了C和我考试中的多态性前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
几天前我接受了C考试,我得到了这个问题,我发现对我来说不清楚,问题是:

Explain the difference among the terms Polymorphism,virtual function and
overriding. By using example getting the area of shape for rectangle and
triangle,write two different snippet codes to show the implementation of
polymorphism and implementation of polymorphism and virtual function.
Give example of output from both snippet codes.

而根据Absolute C 5th p669的多态性定义是:

Polymorphism refers to the ability to associate many meanings to one
function name by means of the late-binding mechanism. Thus,polymorphism,
late binding,and virtual functions are really all the same topic.

我可以从这个定义中理解,没有使用虚函数就没有多态性,不是吗?所以这个问题没有两个不同的片段实现,对吧?只有一个使用虚函数

我的问题是:这是一个有效的问题吗?

解决方法

My question is: Is this a valid question to be asked?

不,它似乎不是关于预期答案“只有虚拟函数在c中提供多态性”.问题太狭隘,误导.

Polymorphism refers to the ability to associate many meanings to one function name by means of the late-binding mechanism. Thus,late binding,and virtual functions are really all the same topic.


我可以从这个定义中理解,不是吗?

实际上你可以在没有虚函数的情况下拥有多态性.

它被称为静态多态,查找CRTP patternSFINAE.

那么,后期绑定的重点实际上缩小了动态多态性和(纯)虚函数的问题.但恕我直言,它仍然是一个糟糕的考试和太狭隘/不明确的问题.

原文链接:https://www.f2er.com/c/110740.html

猜你在找的C&C++相关文章