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,23777acd564d513b X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-01-20 03:39:10 PST Message-ID: <3E2BDFD8.4070805@epfl.ch> Date: Mon, 20 Jan 2003 12:39:04 +0100 From: =?ISO-8859-1?Q?Rodrigo_Garc=EDa?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9) Gecko/20020513 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Problem Eliminating constructors References: <3e274cad$0$33929$bed64819@news.gradwell.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: lglpc31.epfl.ch X-Trace: epflnews.epfl.ch 1043062746 128.178.76.8 (20 Jan 2003 12:39:06 +0200) Organization: EPFL Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!newsfeed.vmunix.org!news.imp.ch!news.imp.ch!news-zh.switch.ch!epflnews.epfl.ch!not-for-mail Xref: archiver1.google.com comp.lang.ada:33233 Date: 2003-01-20T12:39:04+01:00 List-Id: Victor Porton wrote: > package A is > > type A_Type is tagged > record > X: Integer; > end; > > function Create(X: Integer) return A_Type; -- guess what is the body > > end A; > > Then I have > > type B_Type is new A.A_Type with > record > Y: Integer; > end; > > Compiler requires me to override Create as the return type changes. > But it is meaningless as now I need Create with two parameters > instead of one. > > What to do? You do not need a constructor for this simple case. This will create an A_Type object and initialize X to value 5. declare My_A : A.A_Type := (X => 5); Similarly, this will create a B_Type object with X=5 and Y=6. declare My_B : B_Type := (X => 5, Y => 6); Alternatively, you can use discriminants as well: type A_Type (I : Integer) is tagged record X : Integer := I; end record; And then: type B_Type (J : Integer; K : Integer) is new A_Type (I => J) with record Y : Integer := K; end record; With this solution, you are forced to provide initial values in the creation. Rodrigo