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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1dcef85eb875c8db X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-12 04:29:27 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!t-online.de!news1.dtag.de!RRZ.Uni-Koeln.DE!uni-duisburg.de!not-for-mail From: Georg Bauhaus Newsgroups: comp.lang.ada Subject: Re: Dispatching to a common most special ancestor Date: Thu, 12 Jun 2003 11:29:11 +0000 (UTC) Organization: GMUGHDU Message-ID: References: NNTP-Posting-Host: d2-hrz.uni-duisburg.de X-Trace: a1-hrz.uni-duisburg.de 1055417351 21503 134.91.1.15 (12 Jun 2003 11:29:11 GMT) X-Complaints-To: usenet@news.uni-duisburg.de NNTP-Posting-Date: Thu, 12 Jun 2003 11:29:11 +0000 (UTC) User-Agent: tin/1.5.8-20010221 ("Blue Water") (UNIX) (HP-UX/B.11.00 (9000/831)) Xref: archiver1.google.com comp.lang.ada:39044 Date: 2003-06-12T11:29:11+00:00 List-Id: Stephan Heinemann wrote: : function Equals(This, Another: access Object) return Boolean; : ------------------------------------------------------------------ : -- Class Derived_1 ----------------------------------------------- : function Equals(This, Another: access Derived_1) return Boolean; : ------------------------------------------------------------------ : : -- Class Derived_2 ----------------------------------------------- : function Equals(This, Another: access Derived_2) return Boolean; : ------------------------------------------------------------------ : : : I wanted Equals to be dispatched to the common object ancestor but : instead a constraint error is raised. How might I resolve this? First, I would reconsider the accesses all over the place. If they are just there to trigger pass by reference, then they are not needed, as this happens automatically, see RM 6.2: 4 A type is a by-reference type if it is a descendant of one of the following: 5 a tagged type; What you get in addition is an easy way of passing up part of the comparison using just conversion like in, say, function Equals (This: Derived_2; Another: access Derived_2) return Boolean is begin return Equals(Object(This), Object_CA(Another)) and This.Value = Another.Value; end Equals; If I understand your example correctly, you want dispatching to the common object ancestor's Equals if and only if the objects are not of the same type (O1 not in Derived_2 and vice versa), because otherwise there are Equals functions for each of the types in the hierarchy. But that intent is not reflected in the function names, and not by the choice of a specific equals operation for each type, I'd say. There is nothing wrong with comparing objects by various criteria and choosing an appropriate name for each comparison variant ;-) You could for example pass a comparison function tailored for a specific purpose (i.e., not one of those defined for Object and derivatives), as a generic parameter to where it is needed. This function might then, as Dmitry has explained, consume parameters of classwide types, and make the appropriate dispatching-or-not choices. (There was a similar question about a dispatching print recently I think) HTH, georg