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 X-Google-Thread: 103376,23777acd564d513b X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-01-21 01:40:30 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeed.berkeley.edu!ucberkeley!freenix!fr.usenet-edu.net!usenet-edu.net!fu-berlin.de!uni-berlin.de!tar-alcarin.cbb-automation.DE!not-for-mail From: Dmitry A. Kazakov Newsgroups: comp.lang.ada Subject: Re: Problem Eliminating constructors Date: Tue, 21 Jan 2003 10:44:37 +0100 Message-ID: <1n4q2v05i0cn9jnpdelrtroe9l0a7k2noh@4ax.com> References: <3e274cad$0$33929$bed64819@news.gradwell.net> <3e2c66a7$0$33929$bed64819@news.gradwell.net> NNTP-Posting-Host: tar-alcarin.cbb-automation.de (212.79.194.111) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: fu-berlin.de 1043142027 27267876 212.79.194.111 (16 [77047]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:33285 Date: 2003-01-21T10:44:37+01:00 List-Id: On Tue, 21 Jan 2003 02:07:29 +0500, porton@ex-code.com (Victor Porton) wrote: >In article <3E2BDFD8.4070805@epfl.ch>, > Rodrigo Garc�a writes: >> 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); >[skip] > >Oh, Rodrigo, I oversimplified the real situation. Initialization with >just aggregates is possible only in the example, really I need namely >constructor functions. Ada has constructor function. IMO what it does need is user-defined contructors. However, most of Ada people do not share my opinion. In any case (your statement below) constructors always *covariant*. >Well, currently I switched to initialization by calling a procedure. > >It would be nice if Ada0X would allow to make a primitive operation >non-virtual. It is pretty dangerous, so there has to be a strong rationale for this (i.e. to allow contravariant parameters). In your case, you could make Create class-wide, if you want to overload it: function Create (X : Integer) return A_Type'Class; -- creates A_Type function Create (X, Y : Integer) return B_Type'Class; -- creates B_Type --- Regards, Dmitry Kazakov www.dmitry-kazakov.de