comp.lang.ada
 help / color / mirror / Atom feed
From: christoph.grein@eurocopter.com
Subject: Re: Dispatching operations
Date: 8 Nov 2005 04:06:42 -0800
Date: 2005-11-08T04:06:42-08:00	[thread overview]
Message-ID: <1131451602.909774.27570@g47g2000cwa.googlegroups.com> (raw)
In-Reply-To: <dkq1gf$2sv$1@sunnews.cern.ch>

> My confusion is that Op_B is private in P2. X is declared in P2 as well.
> In the above call, I'd expect P2.Op_B to be called (which is actually
> the case), but since everything is known statically, then I'd expect as
> well to get compile-time error due to the fact that P2.Op_B is private.
>
> In other words: how can I get compile error when calling private P2.Op_B?
> If it's not possible, what's the point in making it private?

It's irrelevant whether an operation is overridden visibly or
privately. Always the overriding operation is called, even if not
visible at the place of the call.

There are very subtle effects when overriding privately:

package P1 is
    type T1 is tagged null record;
    procedure Op_B(Arg : in T1; Parm: Integer := 5);
end P1;

with P1; use P1;
package P2 is
    type T2 is new T1 with null record;
private
    procedure Op_B(Param : in T2; Parm: Integer := 0);
end P2;

When calling P2.Op_B, it depends on the local visibility at the place
of the call which default for Parm is used and which name you have to
use in named association for the first parameter.

When the private part of P2 is hidden, Op_B (Arg => X) means Op_B (Arg
=> X, Parm => 5). You do not see the new name of the first parameter.

When the private part is visible, Op_B (Arg => X) is wrong; you have to
write Op_B (Param => X) which means Op_B (Param => X, Parm => 0). You
have to use the new name of the first parameter.




  reply	other threads:[~2005-11-08 12:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-08 11:17 Dispatching operations Maciej Sobczak
2005-11-08 12:06 ` christoph.grein [this message]
2005-11-08 16:15 ` Jeffrey R. Carter
2005-11-09  8:38   ` Maciej Sobczak
2005-11-09 22:28     ` Jeffrey R. Carter
replies disabled

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