抽象类和具体类抽象 [英] abstract classes and concrete class abstract

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

问题描述

当我使用抽象类时?

推荐答案

抽象类主要用于指定接口(i nterface是基本的OOP概念,请务必掌握.)
您只需将纯虚拟方法添加到抽象类(或将现有方法更改为纯虚拟),即可将其转换为抽象类,例如
Abstract classes are mainly used for specify interfaces (interface is a basic OOP concept, make sure to grasp it).
You transform a concrete class into an abstract one simply adding to it a pure virtual method (or changing an existing method to pure virtual), e.g.
// 'Concrete' Foo
class Foo
{
  //... Foo definition
};


// 'Abstract' Foo
class Foo
{
  //... Foo definition
  virtual do_something()=0;
};


C ++中的抽象类至少包含一个纯虚函数,该虚函数定义为:
An abstract class in C++ contains at least one pure virtual function which is a function defined as:
virtual void foo() = 0;

.
这里的重要部分是"= 0"语句.

如果您从抽象类继承,则必须为每个继承的纯虚函数提供函数定义.否则,将无法创建派生类的实例.因此,就C ++而言,无法实例化抽象类.

.
The important part here is the "= 0" statement.

If you inherit from an abstract class you''ll have to provide function definitions for every inherited pure virtual function. Otherwise it is not possible to create an instance of the derived class. Hence in terms of C++ it is not possible to instantiate abstract classes.


第一个问题的答案:-

http://www.brpreiss.com/books/opus4/html/page611.html

我希望这能消除您的困惑.

谢谢
Answer to your first question:-

19,000,000 results for when to use an abstract class

Now, why do you require to make a concrete class abstract? As:-

http://www.brpreiss.com/books/opus4/html/page611.html

I hope this will clear out your confusion.

Thanks


这篇关于抽象类和具体类抽象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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