C++ 中的抽象类声明 [英] abstract class declarations in c++

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

问题描述

假设foo是C++程序中的一个抽象,为什么声明foo*<类型的变量是可以接受的/code>,但不是 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屋!

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