抽象类是否可以作为其他具体类的成员构成关系? C ++ [英] Can an abstract class be member of other concrete class as composition relationship ? c++
本文介绍了抽象类是否可以作为其他具体类的成员构成关系? C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
P是一个抽象类,我想使其成为类A的成员,后者是普通的具体类.如果可以的话,有可能吗?关系是组成 感谢您的帮助
P is an abstract class, I want to make it member of class A which is a normal concrete class. Is it possible if yes how. Relationship is composition Thanks for help
推荐答案
由于P
是抽象的,因此您永远无法创建该类型的对象.但是,您可以将指向P
的指针存储为类A
的成员.然后,该指针成员可以指向P
的(具体)子类的实例.
Since P
is abstract, you can never create an object of that type. However, you can store a pointer to P
as a member of class A
; this pointer member could then point to an instance of a (concrete) subclass of P
.
这篇关于抽象类是否可以作为其他具体类的成员构成关系? C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文