为什么我们不能建立一个抽象基类的对象,它的用途和好处是什么 [英] Why we can't ceate a object of Abstract base class and what is its used and benifits

查看:113
本文介绍了为什么我们不能建立一个抽象基类的对象,它的用途和好处是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,先生,
我知道我们无法创建抽象类的对象.因为抽象类具有纯虚函数.但是我感到困惑的是,为什么我们不能创建抽象基类的对象,它的用途和用途是什么?编程.虽然我们可以创建具有虚拟功能的类的对象.


谢谢
Amrit Kumar

Hello Sir,
I know that we can''t create an object of an abstract class.Because a abstract class have pure virtual function .But i have a confusion that why we can not create an object of abstract base class and what is its benifit and use in programing . While we can create an object a class which have virtual function.


Thanks
Amrit Kumar

推荐答案

抽象类无法实例化,因为它缺少位(纯虚函数没有主体),必须由继承它的类来实现.我不关心它是基础链还是下行链的100层,如果它是抽象的,那么它就不能独立存在.

另一方面,虚函数(不是纯函数)是可以在实现类中覆盖的虚函数.
An abstract class cannot be instantiated because it has bits missing (the pure virtuals have no body), which must be implemented by a class that inherits it. I matters not whether it is base or 100 levels down the chain, if it is abstract then it cannot exist on its own.

A virtual function on the other hand (not pure) is one which can be overridden in an implementing class.


嗯,这与您的应用程序结构的设计以及类需要的方式有关实施/继承.

抽象类的目的是提供多个派生类可以共享的基类的通用定义. abstract关键字使您可以创建不完整的类和类成员,并且必须在派生类中实现.

在这里阅读有关它的更多信息:抽象和密封的类和类成员 [
Well, this is related to the designing of your application artictecture and the way classes needs to implemented/inherited.

The purpose of an abstract class is to provide a common definition of a base class that multiple derived classes can share. The abstract keyword enables you to create classes and class members that are incomplete and must be implemented in a derived class.

Read more about it here: Abstract and Sealed Classes and Class Members[^]


这篇关于为什么我们不能建立一个抽象基类的对象,它的用途和好处是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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