C ++中的抽象类声明 [英] abstract class declarations in c++
本文介绍了C ++中的抽象类声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设 foo
是C ++程序中的抽象 类
,为什么呢?是否可接受声明 foo *
类型的变量,但不能声明 foo
类型的变量?
Suppose foo
is an abstract class
in a C++ program, why is it acceptable to declare variables of type foo*
, but not of type foo
?
推荐答案
因为如果声明foo,则必须对其进行初始化/实例化。如果声明了* foo,则可以使用它指向从foo继承但不是抽象的类的实例(因此可以实例化)
Because if you declare a foo you must initialize/instantiate it. If you declare a *foo, you can use it to point to instances of classes that inherit from foo but are not abstract (and thus can be instantiated)
这篇关于C ++中的抽象类声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文