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

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

问题描述

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

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天全站免登陆