抽象方法和虚拟方法有什么区别? [英] What is the difference between an abstract method and a virtual method?

查看:71
本文介绍了抽象方法和虚拟方法有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

抽象方法和虚拟方法之间有什么区别?建议在哪种情况下使用抽象或虚拟方法?哪一种是最好的方法?

What is the difference between an abstract method and a virtual method? In which cases is it recommended to use abstract or virtual methods? Which one is the best approach?

推荐答案

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

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.

这篇关于抽象方法和虚拟方法有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆