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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3a34550290fdc12c X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-07-14 18:30:40 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!stamper.news.atl.earthlink.net!harp.news.atl.earthlink.net!not-for-mail From: Richard Riehle Newsgroups: comp.lang.ada Subject: Re: Problems with tagged records and inheritance Date: Mon, 14 Jul 2003 18:34:06 -0700 Organization: AdaWorks Software Engineering Message-ID: <3F135A0E.A46C33D1@adaworks.com> References: Reply-To: richard@adaworks.com NNTP-Posting-Host: 41.b2.41.e1 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Server-Date: 15 Jul 2003 01:30:40 GMT X-Mailer: Mozilla 4.7 [en] (Win98; I) X-Accept-Language: en Xref: archiver1.google.com comp.lang.ada:40274 Date: 2003-07-15T01:30:40+00:00 List-Id: I am including your posting at the end of this reply. First, you have a visibility problem because type Base is private and its contents are not visible. Also, you have a design problem. Consider, package The_Base is type Base is tagged private; procedure Put(B : Base); private type Base is tagged record AAA : Integer := 42; end record; end Base; Now you have a design with a primitive operation for Base. You would need more of these, of course. package Derived_From_Base is type Derived is new The_Base.Base with private; procedure Put(D : Derived); private type Derived is new The_Base.Base with record BBB : Integer := 451; end record; end Derived_From_Base; Now you have a derived type along with a primitive Put method for it. You implement the Put in terms of the existing Put in The_Base. with Ada.Integer_Text_IO; package body Derived_From_Base is procedure Put(D : Derived) is begin The_Base.Put(The_Base.Base(D)); Ada.Integer_Text_IO.Put(BBB); end Put; end Derived_From_Base; One of the key ideas behind object-oriented programming is that of reuse. In the Put method for Derived you are first reusing the implementation of the Put for its parent and then coding the part for the immediately visible type. Hope this helps. I did not compile this so there might be some typos, but the fundamental idea is there. Richard Riehle Papastefanos Serafeim wrote: > I have using a base type like this: > ... > type Base is tagged private; > ... > type Base is tagged record > AAA: Integer:=1; > end record; > > and a child type like this > > type Child is new Base with private; > .... > type Child is new Base with record > BBB: Integer:=5; > end record; > > The problem is that the following is not working: > > procedure Test(Ch: in Child) is > begin > Put(Ch.AAA); --<- This line has an error, it says no selector AAA for > type Child > Put(Ch.BBB); > end Test; > The procedure Test is declared in the same package > as the type Child and defined at the package's Body. > > The error is becouse AAA is not part of Child. > Why is that ? I thought that Child would contain > AAA and BBB, and not only BBB... > > -- > Papastefanos Serafeim > serafeim@otenet.gr