什么是一个抽象的函数和虚函数的区别? [英] What is the difference between an abstract function and a virtual function?

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

问题描述

在这情况下,最好先使用虚拟的或抽象的?这是比较正确的做法?

In which cases is it recommended to use virtual or abstract? Which is the more correct 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天全站免登陆