comp.lang.ada
 help / color / mirror / Atom feed
* Can't find the answer
@ 1997-11-22  0:00 Van Snyder
  1997-11-22  0:00 ` Matthew Heaney
  0 siblings, 1 reply; 2+ messages in thread
From: Van Snyder @ 1997-11-22  0:00 UTC (permalink / raw)



I looked in the Ada-95 standard, and in Barnes's book, and in
Cohen's book, for the answer to the following question.  I
remember reading the answer long ago, but I forgot which way
it went.  And where I read it.

Suppose I have a type T1, and extend it to a type T2.

Suppose I have a procedure P that takes an argument of type T1,
not T1'class.

Can I invoke P directly on an object of type T2?  Not a classwide
object of T1'class, and not an object of type T2 converted explicitly
to T1 by T1().

E-mail would help me most, but post, too, if you like.

Van Snyder
vsnyder@gyre.jpl.nasa.gov
-- 
What fraction of Americans believe   |  Van Snyder
Wrestling is real and NASA is fake?  |  vsnyder@math.jpl.nasa.gov




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Can't find the answer
  1997-11-22  0:00 Can't find the answer Van Snyder
@ 1997-11-22  0:00 ` Matthew Heaney
  0 siblings, 0 replies; 2+ messages in thread
From: Matthew Heaney @ 1997-11-22  0:00 UTC (permalink / raw)



In article <655s7e$ei9@netline.jpl.nasa.gov>, vsnyder@math.jpl.nasa.gov
(Van Snyder) wrote:


>Suppose I have a type T1, and extend it to a type T2.
>
>Suppose I have a procedure P that takes an argument of type T1,
>not T1'class.
>
>Can I invoke P directly on an object of type T2?  Not a classwide
>object of T1'class, and not an object of type T2 converted explicitly
>to T1 by T1().

I assume that the types are tagged, since you're talking about T'Class.

Yes, you can invoke the operation P on an object of T2, if the operation
was a "primitive" operation of T1.  By "primitive" I mean the subprogram
was declared in the same package spec as the declaration of the type
itself.  If so, type T2 inherited the P operation when it derived from T1. 
(Actually, here it doesn't make any difference whether the type is tagged.)

Here's an example:

package Q1 is

   type T1 is tagged record ...;

   procedure P (O : T1);

end;

P is a primitive operation of type T1.  So when I derive from T1, ie

with Q1;
package Q2 is

   type T2 is new Q1.T1 with ...;
 
-- procedure P (O : T2);  -- is implicitly declared here

end Q2;

Now, had package Q1 looked like

package Q1 is

   type T1 is tagged ....;

   package Inner is

      procedure P (O : T1);

   end Inner;

end Q1;

then P is no longer a "primitive" operation of T1; it's just a plain old
operation.  Therefore it would not be inherited by T2.

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1997-11-22  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-11-22  0:00 Can't find the answer Van Snyder
1997-11-22  0:00 ` Matthew Heaney

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