且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

抽象方法和虚拟方法有什么区别?

更新时间:2023-09-23 22:33:22

抽象函数不能具有功能.您基本上是在说,任何子类都必须提供自己的此方法版本.这太笼统了,甚至无法尝试在父类中实现.

An abstract function cannot have functionality. You're basically saying, any child class MUST give their own version of this method, however it's too general to even try to implement in the parent class.

虚拟功能基本上是说外观,以下功能对于子类而言可能足够好,也可能不够好.因此,如果足够好,请使用此方法;否则,请覆盖我并提供您自己的功能.

A virtual function, is basically saying look, here's the functionality that may or may not be good enough for the child class. So if it is good enough, use this method, if not, then override me, and provide your own functionality.