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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: child class of limited_controlled not inheriting data Date: Fri, 5 Aug 2016 21:37:58 +0200 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: xelDFTENDI+dlkJFd2Ot2w.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:31300 Date: 2016-08-05T21:37:58+02:00 List-Id: On 2016-08-05 20:59, b.mcguinness747@gmail.com wrote: > I defined a base class as > > > with Ada.Float_Text_IO; > with Ada.Finalization; > > package sofa.time.two_part_date is > type Date is new Ada.Finalization.Limited_Controlled with private; > > function To_Date (days : Integer; fraction : Real) return Date; > function To_Date (time_string : String) return Date; > > function "<" (left, right : Date) return Boolean; > function "<=" (left, right : Date) return Boolean; > function "=" (left, right : Date) return Boolean; > function ">=" (left, right : Date) return Boolean; > function ">" (left, right : Date) return Boolean; > > procedure Add_Days (this : in out Date; days : in Integer; fraction : in Real); > > function Get_Day_Count (this : Date) return Integer; > function Get_Day_Fraction (this : Date) return Real; > function To_Real (this : Date) return Real; > function To_String (this : Date) return String; > > private > type Date is new Ada.Finalization.Limited_Controlled with record > day_count : Integer; > day_fraction : Real; -- Normalized to 0.0 <= x < 1.0 > end record; > > overriding procedure Initialize (this: in out Date); > overriding procedure Finalize (this: in out Date); > > procedure Normalize (day_count : in out Integer; day_fraction : in out Real); > end; > > (It's Limited_Controlled because I want to force day_fraction to be > normalized when objects of the class are created.) It must be Controlled if some complicated initialization required, and likely abstract, not Limited_Controlled. > Then I defined a child class as > > with sofa.time.two_part_date; > > package sofa.time.Julian_Day_Numbers is [...] > When I try to compile the child class, I get error messages such as > > sofa-time-julian_day_numbers.adb:77:79: "day_count" is not a > component of type "Julian_Day_Number" defined at sofa-time-julian_day_numbers.ads:4 > > indicating that the child class is not inheriting the data from the parent class. > > What is wrong here? You didn't make day_count visible. There are three ways to do it, in the order of publicity: 1. Make it a public member 2. Make it available through getter/setter. You have Get_Day_Count, if that is, then use it in Julian_Day_Numbers. 3. Make Julian_Day_Numbers child package: sofa.time.two_part_date.Julian_Day_Numbers -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de