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,68b702bd2264cada X-Google-Attributes: gid103376,public From: Ray Blaak Subject: Re: Dynamic redispatching Date: 2000/01/18 Message-ID: #1/1 X-Deja-AN: 574586178 Sender: blaak@baka.infomatch.bc.ca References: <862gtg$meu$1@nnrp1.deja.com> X-Trace: news.bctel.net 948266163 207.34.170.120 (Tue, 18 Jan 2000 23:16:03 PDT) NNTP-Posting-Date: Tue, 18 Jan 2000 23:16:03 PDT Newsgroups: comp.lang.ada X-Complaints-To: news@bctel.net Date: 2000-01-18T00:00:00+00:00 List-Id: Ted Dennison writes: > I'm trying to write a classwide function that dynamicly redispatches > based on the tag of the function result. But it isn't dispatching on > either of the two Ada compilers I tried. Here's an example: [...] > function Main_Dispatcher return Class is > begin > return Dispatch; > end Main_Dispatcher; [...] > procedure Test is > Item : P1.Handle := new P2.Instance; > begin > Item.all := P1.Main_Dispatcher; > end Test; > > When I run Test, of course I want it to dispatch to P2.Dispatch and > return a value of type P2.Instance. The problem is that you need an object to dispatch on. There is no information inside Main_Dispatcher to decide which Dispatch to call, since by the time the object is returned, it is too late (or more accurately, you are specifying only to call P1.Dispatch). In the statement "Item.all := P1.Main_Dispatcher", the contents of Item are irrelevant, since only Main_Dispatcher can be called. Inside Main_Dispatcher, no information about the result destination is known. Perhaps this would work: Item.all := P1.Dispatch; For then we have a function with a controlling result (I think), and it should thus use the context (the tag of the destination) to dispatch. I think the main problem was that Main_Dispatcher is not a primitive operation of P1.Instance -- Cheers, The Rhythm is around me, The Rhythm has control. Ray Blaak The Rhythm is inside me, blaak@infomatch.com The Rhythm has my soul.