comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <sb463ba@d2-hrz.uni-duisburg.de>
Subject: Re: Dispatching to a common most special ancestor
Date: Thu, 12 Jun 2003 11:29:11 +0000 (UTC)
Date: 2003-06-12T11:29:11+00:00	[thread overview]
Message-ID: <bc9o67$kvv$1@a1-hrz.uni-duisburg.de> (raw)
In-Reply-To: bc8cnl$in0$1@news.cs.tu-berlin.de

Stephan Heinemann <zombie@cs.tu-berlin.de> 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



  parent reply	other threads:[~2003-06-12 11:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-11 23:07 Dispatching to a common most special ancestor Stephan Heinemann
2003-06-12  6:08 ` Dmitry A. Kazakov
2003-06-12 11:29 ` Georg Bauhaus [this message]
2003-06-12 15:03 ` Matthew Heaney
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox