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-Thread: 103376,342dcd67e9ca73ee X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: tagged record child: override constructor? Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1126591134.797303.318920@z14g2000cwz.googlegroups.com> Date: Tue, 13 Sep 2005 09:32:58 +0200 Message-ID: <1uri5gd2n7om0.1ujkzb26ayxdx.dlg@40tude.net> NNTP-Posting-Date: 13 Sep 2005 09:32:54 MEST NNTP-Posting-Host: 313c9b7d.newsread2.arcor-online.net X-Trace: DXC=k4n?D9BSA]\@WLLO>ILfT_WRXZ37ga[7Zn919Q4_`VjYB8=X\UUgbkT X-Complaints-To: abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:4601 Date: 2005-09-13T09:32:54+02:00 List-Id: On 12 Sep 2005 22:58:54 -0700, sean.gilbertson@gmail.com wrote: > I have a tagged record that is declared private, along with a > constructor function which returns an instance. I do this to enforce > the assignment of several required fields in the record, so if you know > how to do this another way, please let me know! Ada.Finalization? > But Ada is telling me I have to override this function in the child. I presume you have something like: type X is private; function Create (...) return X; private type X is tagged ...; > This doesn't make a lot of sense. On the contrary, Create above is covariant, that means that a derived type cannot inherit it, because otherwise the result would be of the parent type X. Thus it has to be overridden in each derived type. This is a very important feature that saves a lot of debugging. > How can I deal with this? Just make Create contravariant, provided that you know how to create derived instances from there. In Ada contravariant subroutines are class-wide: type X is tagged private; -- Publicly tagged to have an ability to declare class-wides function Create (...) return X'Class; -- This is same for all derived types private type X is tagged ...; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de