comp.lang.ada
 help / color / mirror / Atom feed
* I am confused
@ 1997-10-11  0:00 mrada
  1997-10-11  0:00 ` Robert A Duff
  1997-10-11  0:00 ` Matthew Heaney
  0 siblings, 2 replies; 3+ messages in thread
From: mrada @ 1997-10-11  0:00 UTC (permalink / raw)



Hi all,

I have the following example which I can't seem to get to compile right.
My goal is to create a table containing pointers to functions which
have as parameters an item of a class rooted at Z.  What am I missing?

package S is

  type Z is tagged record
    Y : Integer;
  end record;

  type CB  is access procedure (Item : in out Z'class);
  type CBs is array (1 .. 10) of CB;

  type X is new Z with record
    W : Float;
  end record;

  procedure A (Item : in out X'class);

  B : CBs := (1 .. 10 => A'access);

end S;

Chris Sparks




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

* Re: I am confused
  1997-10-11  0:00 I am confused mrada
  1997-10-11  0:00 ` Robert A Duff
@ 1997-10-11  0:00 ` Matthew Heaney
  1 sibling, 0 replies; 3+ messages in thread
From: Matthew Heaney @ 1997-10-11  0:00 UTC (permalink / raw)



In article <343F837F.388C4905@catalina-inter.net>, mrada
<mrada@CATALINA-INTER.NET> wrote:


>package S is
>
>  type Z is tagged record
>    Y : Integer;
>  end record;
>
>  type CB  is access procedure (Item : in out Z'class);
>  type CBs is array (1 .. 10) of CB;
>
>  type X is new Z with record
>    W : Float;
>  end record;
>
>  procedure A (Item : in out X'class);
>
>  B : CBs := (1 .. 10 => A'access);
>
>end S;

What was the error message?  Aren't Z'Class and X'Class different types? 
The component subtype of array B designates a subprogram whose parameter is
of type Z'Class, yet the subprogram A has type X'Class as its parameter. 
Is that the problem?

Going to TRI-Ada, Chris?

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




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

* Re: I am confused
  1997-10-11  0:00 I am confused mrada
@ 1997-10-11  0:00 ` Robert A Duff
  1997-10-11  0:00 ` Matthew Heaney
  1 sibling, 0 replies; 3+ messages in thread
From: Robert A Duff @ 1997-10-11  0:00 UTC (permalink / raw)



In article <343F837F.388C4905@catalina-inter.net>,
mrada  <mrada@CATALINA-INTER.NET> wrote:
>  type Z is tagged record
>    Y : Integer;
>  end record;
>
>  type CB  is access procedure (Item : in out Z'class);
>  type CBs is array (1 .. 10) of CB;
>
>  type X is new Z with record
>    W : Float;
>  end record;
>
>  procedure A (Item : in out X'class);
>
>  B : CBs := (1 .. 10 => A'access);

This is illegal because A doesn't match the profile declared to type CB.
Note that if this were allowed, then somebody might call B(3), passing
it a parameter of type Z, but procedure A is expecting an X, so that
would be a nasty hole in the type system.

You might want to declare a procedure A on type Z'Class.  You might want
to have it dispatch to some type-specific procedure.

- Bob




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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-10-11  0:00 I am confused mrada
1997-10-11  0:00 ` Robert A Duff
1997-10-11  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