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,d768e222992aaaab,start X-Google-Attributes: gid103376,public From: Kevin Ingalls Subject: Dispatching In Generics Date: 1997/06/05 Message-ID: <3396EB36.3D14@boeing.com>#1/1 X-Deja-AN: 246691727 Sender: nntp@bcstec.ca.boeing.com (NNTP News Access) X-Nntp-Posting-Host: 137.136.74.69 Organization: The Boeing Company Newsgroups: comp.lang.ada Date: 1997-06-05T00:00:00+00:00 List-Id: First, I can't find the Ada FAQ, so perhaps the answer to my question is there. If you know where it is I would appreciate the address. Second, here is my coding question: How do I code a generic so that it can take the base type of a hierarchy and perform dispatching on objects of that type? Specifically, given: package A with an abstract tagged type X a primitive operation "operation" on type X child package A.B with a derived type Y a primitive operation "operation" on type Y How do I write a generic that can handle objects of X'class, including dispatching operations correctly? Here is the skeleton of a first try: ---------------------------- with ada.finalization; package A is type X is abstract tagged private; procedure operation (anX : X); private type X is abstract new ada.finalization.controlled with... end A; package A.B is type Y is new X with private; procedure operation (aY : Y); private type Y is new X with record... end A.B; generic type T is abstract tagged private; with procedure op (aT : T); package gPackage is procedure P; end gPackage; package body gPackage is procedure P is begin op (object_of_type_T); -- here is the syntax error end P; end gPackage; with A, gPackage; package instance is new gPackage(A.X, A.operation); ---------------------------- The syntax error occurs while compiling the generic on the marked line. I understand that I have no subprograms with class-wide parameters, and so "op" cannot do dispatching (which is what the error message tells me). The question is, what is the correct way to accomplish this? As a kludge, I added a class-wide operation to package A for type X: ---- procedure operation_class_wide (aClassWideX : X'class); ---- procedure operation_class_wide (aClassWideX : X'class) is begin operation(aClassWideX); end operation_class_wide; And changed the instantiation to: package instance is new gPackage (A.X, A.operation_class_wide); But this is hardly a clean solution. So, the question is how can I write a generic package to handle a class hierarchy, including dispatching-like behavior, cleanly? -- Kevin Ingalls, (206)773-9404, kevin.l.ingalls@boeing.com