From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,68c80d9ad156e257 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1995-03-24 04:20:26 PST Newsgroups: comp.lang.ada Path: nntp.gmd.de!news.rwth-aachen.de!news.rhrz.uni-bonn.de!news.uni-stuttgart.de!rz.uni-karlsruhe.de!xlink.net!howland.reston.ans.net!gatech!purdue!news.bu.edu!inmet!spock!stt From: stt@spock.camb.inmet.com (Tucker Taft) Subject: Re: Type extension questions Message-ID: Sender: news@inmet.camb.inmet.com Organization: Intermetrics, Inc. X-Newsreader: TIN [version 1.1 PL8] References: Date: Thu, 23 Mar 1995 22:03:59 GMT Date: 1995-03-23T22:03:59+00:00 List-Id: Harry Koehnemann (koehnema@enuxsa.eas.asu.edu) wrote: : I have a couple questions on Ada95 tagged types. These appear to be : easy questions, but I can't seem to locate an answer for either. : LRM references would also be appreciated with an answer. : 1) Is it possible to derive a type such that the parent operations are not : available to the user of the new type? This question is equivalent to : the ability to do private inheritance ala C++ - class B: private A { ...}; : I would assume the answer is yes, but haven't yet figured out how. Just declare the new type as a tagged private type (RM95 7.3(2)): type T is tagged private; ... private type T is new P with record ... Or, if you want to make it visible that you are derived from some ancestor of P, but not that you are derived from P directly (see RM95 7.3(3)): type T is new P_Ancestor with private; ... private type T is new P with record ... -- presuming P is descended from P_Ancestor Even simpler is to use the "privately" inherited type as a component. In many cases, type extension is overkill for purely private "implementation" inheritance. Simply making P a component eliminates any complexity relating to multiple inheritance, etc. : 2) Can a derived type declare a component with the same name as a parent : component? At the risk of being lectured on GNAT's incompleteness :), : GNAT allows a new same-name components if the parent type is private and : the child type is public, but does gives an error if the child and parent : are both public or private. I assume the answer is one or the other, : not "if one is private and one is public...". Other OO languages allow : this in their inheritance and I assume Ada95 does as well. Only inherited subprograms can be overridden; inherited components cannot (RM95 8.3(9-13)). You may not repeat names if both components would ever be visible at the same place (RM95 8.3(26)). This rule is repeated as a Note in RM95 3.9.1(9) -- Note #69 of Section 3. What this means is that you can reuse a name of a non-discriminant component only if the parent type is private. You can reuse the name of a (visible) discriminant of the parent only if a new discriminant_part is given in the declaration of the type extension. Even if the parent type is private, you can't reuse the name if the record extension is declared in a child of the package containing the private type declaration, because once you get to the private part or body of the child, both would be visible (RM95 7.3.1(4)). (I fear that as I now reread 7.3.1(4) and 8.3(26), the intent of these rules for handling this special case might have gotten a bit garbled in the RM-ease...) : Thanks. : -- : Harry Koehnemann Arizona State University : hek@asu.edu Computer Science Department -Tucker Taft stt@inmet.com Intermetrics, Inc.