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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,87557ce53b069315,start X-Google-Attributes: gid103376,public From: "Matthew Heaney" Subject: meaning of "current instance" Date: 1999/11/11 Message-ID: <382b0da1_2@news1.prserv.net>#1/1 X-Deja-AN: 547422819 Content-transfer-encoding: 7bit Content-Type: text/plain; charset="US-ASCII" X-Complaints-To: abuse@prserv.net X-Trace: 11 Nov 1999 18:40:33 GMT, 32.101.8.196 Organization: Global Network Services - Remote Access Mail & News Services Mime-version: 1.0 Newsgroups: comp.lang.ada Date: 1999-11-11T00:00:00+00:00 List-Id: I have some code below that I thought had a bug (um, I mean "error"), but now I'm not so sure. Suppose I have this: type T is tagged private; ... function Init (O : access T'Class) type T is tagged record I : Integer := Init (T'Access); end record; If I have an object of type T: declare O1 : T; begin then it's clear that the "current instance" to which T'Access refers has type T. But now suppose I derive from T: type NT is new T with null record; and declare an instance of type NT: declare O2 : NT; begin Object O2 (like O1) has a component I, which is initialized with the "current instance." But what is the type of the "current instance" here, passed to Init? --STX with Ada.Text_IO; use Ada.Text_IO; package body P.C is function Do_Init (O : access NT) return Integer is begin Put_Line ("P.C.Do_Init"); return 1; end; end P.C; package P.C is type NT is new T with null record; private function Do_Init (O : access NT) return Integer; end P.C; with Ada.Text_IO; use Ada.Text_IO; package body P is procedure Put (O : in T'Class) is begin Put_Line ("I is" & Integer'Image (O.I)); end; function Init (O : access T'Class) return Integer is begin Put_Line ("P.Init"); return Do_Init (O); end; function Do_Init (O : access T) return Integer is begin Put_Line ("P.Do_Init"); return 0; end; end P; package P is type T is tagged limited private; procedure Put (O : in T'Class); private function Init (O : access T'Class) return Integer; function Do_Init (O : access T) return Integer; type T is tagged limited record I : Integer := Init (T'Access); end record; end P; with P; use P; with P.C; use P.C; procedure Test_P is OT : T; ON : NT; begin Put (OT); Put (ON); end;