简体   繁体   中英

A general declaration for all inherited classes

Consider, there is a class called SuperClass from which, ClassA , ClassB , ClassC is derived. 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].

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 .

Is there a possible way to do it?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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