- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
几天前我参加了 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, polymorphism, late binding, and virtual functions are really all the same topic.
我可以从这个定义中理解不使用虚函数就没有多态性,不是吗?
实际上,您可以在没有 virtual
函数的情况下拥有多态性。
这叫做静态多态,查找CRTP pattern和 SFINAE .
嗯,后期绑定(bind) 的强调实际上缩小了动态多态性和(纯)虚拟
函数的问题。但恕我直言,这仍然是一个糟糕的考试,而且问题太狭窄/不明确。
关于c++ - C++ 中的多态性和我的考试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35092873/
我来自 Asp.Net 世界,试图理解 Angular State 的含义。 什么是 Angular 状态?它类似于Asp.Net中的ascx组件吗?是子页面吗?它类似于工作流程状态吗? 我听到很多人
我一直在寻找 3 态拨动开关,但运气不佳。 基本上我需要一个具有以下状态的开关: |开 |不适用 |关 | slider 默认从中间开始,一旦用户向左或向右滑动,就无法回到N/A(未回答)状态。 有人
我是一名优秀的程序员,十分优秀!