简体   繁体   English

所有继承类的一般声明

[英]A general declaration for all inherited classes

Consider, there is a class called SuperClass from which, ClassA , ClassB , ClassC is derived. 考虑一下,有一个叫做SuperClass的类, ClassC可以派生ClassAClassBClassC From each one of those derived Classes, there are further more two classes are derived each called ChildClassAA and ChildClassAB [AB stands for Bth Child class from the Ath Class.Lets not really pull our hair on this nomenclature]. 从这些派生类的每个派生类中,又派生出两个类,分别称为ChildClassAAChildClassAB [AB代表Ath类中的Bth Child类。因此,请不要真正使用这种命名法。

Now, ideally, I want to declare a general type as a private member of another Class say IndependentClass which can be initialized during run time as either of the objects of type ClassA or ClassB or ClassC and even the derived classes like ClassAA or ClassAB . 现在,理想情况下,我想为另一个类的私有成员说来声明一个普通型IndependentClass可以在运行时为任一类型的对象的初始化ClassAClassBClassC ,甚至派生类,如ClassAAClassAB

Is there a possible way to do it? 有没有办法做到这一点?

如果我理解正确,那么由于所有这些类都是(直接或间接地)从SuperClass ,因此您只需将字段声明为SuperClass类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM