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,2045dce6c7815bab X-Google-Attributes: gid103376,public From: Samuel Tardieu Subject: Re: access types and dispatching subprograms Date: 1996/06/25 Message-ID: #1/1 X-Deja-AN: 162012474 sender: tardieu@gargantua.enst.fr references: <4qjqre$44lo@news-s01.ny.us.ibm.net> to: kbrun@ibm.net content-type: text/plain; charset=iso-8859-1 organization: TELECOM Paris mime-version: 1.0 newsgroups: comp.lang.ada Date: 1996-06-25T00:00:00+00:00 List-Id: >>>>> "Klaus" == kbrun writes: Klaus> I have some trouble with Ada95 dispatching subprograms and Klaus> access types. AFAIK, a proc. call should dispatch if all Klaus> corresponding actual parameters are of (*or pointing to*) type Klaus> T'Class and if the formal parameters are of (*or pointing to*) Klaus> type T. Still, the following code sample doesn't work. It seems you haven't well understood how dispatching works. The "compiler error" (in fact "invalid parameter list in call") seems correct, because there is no procedure "disp" whose formals are of type TC_p. Dispatching works on subprograms whose first parameter is of a tagged type (or access to a tagged type) (in fact all the parameters of the same hierarchy of tagged types). What you probably want to do is: package T is type T is tagged null record; procedure Disp (P : access T); type T1 is new T with null record; procedure Disp (P : access T1); type TC_p is access all T'Class; procedure Do_Dispatch; end T; with Ada.Text_IO; use Ada.Text_IO; package body T is procedure Disp (P : access T) is begin Put_Line ("access T"); end Disp; procedure Disp (P : access T1) is begin Put_Line ("access T1"); end Disp; procedure Do_Dispatch is ClassP : constant TC_p := new T1; begin Disp (ClassP); end Do_Dispatch; end T; with T; procedure Test is begin T.Do_Dispatch; end Test; Execution gives: % ./test access T1 which is what you want. Sam PS/ Note the use of access parameters (and not parameters of an access type) -- Samuel Tardieu -- sam@ada.eu.org