comp.lang.ada
 help / color / mirror / Atom feed
* Should the compiler accept this?
@ 2001-10-10 16:57 Stephen Cole
  2001-10-10 17:11 ` Ted Dennison
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Stephen Cole @ 2001-10-10 16:57 UTC (permalink / raw)


Hi

Simple question 2......

package MyTstTypes is
   type MyRcd is abstract tagged
      record
         a: Integer;
         b: Float;
      end record;

   function Hello(A: MyRcd) return Integer is abstract;

   type MyNewRcd is new MyRcd with
      record
         c: Integer;
      end record;

   function Hello(A: MyNewRcd) return Integer;

   type MyNewRcd2 is new MyNewRcd with
      record
         d: Float;
      end record;

   function Add(A: MyRcd'class) return Integer;

end MyTstTypes;

The compiler is not complaining about it, but according to the rules of Ada
and not just what the compiler accepts, should I be defining a function
Hello() for derived type MyNewRcd2?? Or can I always assume that the Hello()
defined for type MyNewRcd will actually catch calls to Hello() made with an
actual MyNewRcd2 type variable passed as a parameter to Add()?








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

* Re: Should the compiler accept this?
  2001-10-10 16:57 Should the compiler accept this? Stephen Cole
@ 2001-10-10 17:11 ` Ted Dennison
  2001-10-10 17:12 ` Ed Falis
  2001-10-11  8:48 ` Stephen Cole
  2 siblings, 0 replies; 4+ messages in thread
From: Ted Dennison @ 2001-10-10 17:11 UTC (permalink / raw)


In article <9q1uah$6ir$1@trog.dera.gov.uk>, Stephen Cole says...
>The compiler is not complaining about it, but according to the rules of Ada
>and not just what the compiler accepts, should I be defining a function
>Hello() for derived type MyNewRcd2?? Or can I always assume that the Hello()
>defined for type MyNewRcd will actually catch calls to Hello() made with an
>actual MyNewRcd2 type variable passed as a parameter to Add()?

The only time you *have* to define an overriding subprogram is when the parent's
version of the subprogram was abstract. Otherwise, you can just let it dispatch
to the parent's subprogram (which it will do).

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html

No trees were killed in the sending of this message. 
However a large number of electrons were terribly inconvenienced.



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

* Re: Should the compiler accept this?
  2001-10-10 16:57 Should the compiler accept this? Stephen Cole
  2001-10-10 17:11 ` Ted Dennison
@ 2001-10-10 17:12 ` Ed Falis
  2001-10-11  8:48 ` Stephen Cole
  2 siblings, 0 replies; 4+ messages in thread
From: Ed Falis @ 2001-10-10 17:12 UTC (permalink / raw)


Stephen Cole wrote:

> The compiler is not complaining about it, but according to the rules of Ada
> and not just what the compiler accepts, should I be defining a function
> Hello() for derived type MyNewRcd2?? Or can I always assume that the Hello()
> defined for type MyNewRcd will actually catch calls to Hello() made with an
> actual MyNewRcd2 type variable passed as a parameter to Add()?

No, because you're deriving MyNewRcd2 from MyNewRcd, which does provide
a concrete version of Hello, and which is inheritied by MyNewRcd2.  If
you'd derived MyNewRcd2 directly from MyRcd, you would have had to
provide a specific concrete Hello for it.

- Ed



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

* Re: Should the compiler accept this?
  2001-10-10 16:57 Should the compiler accept this? Stephen Cole
  2001-10-10 17:11 ` Ted Dennison
  2001-10-10 17:12 ` Ed Falis
@ 2001-10-11  8:48 ` Stephen Cole
  2 siblings, 0 replies; 4+ messages in thread
From: Stephen Cole @ 2001-10-11  8:48 UTC (permalink / raw)


Thanks!





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

end of thread, other threads:[~2001-10-11  8:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-10 16:57 Should the compiler accept this? Stephen Cole
2001-10-10 17:11 ` Ted Dennison
2001-10-10 17:12 ` Ed Falis
2001-10-11  8:48 ` Stephen Cole

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