comp.lang.ada
 help / color / mirror / Atom feed
* Q: Access subprogram with class type parameters
@ 2000-03-08  0:00 Rush Kester
  2000-03-09  0:00 ` Ted Dennison
  0 siblings, 1 reply; 2+ messages in thread
From: Rush Kester @ 2000-03-08  0:00 UTC (permalink / raw)


This is my first attempt at using subprogram access types and class
programming.

Why doesn't Default_Get_Procedure match Get_Procedure in the following?

with text_io;
procedure test is
   type Values is
      tagged record
         null;
      end record;
   type Bool_Values          is new Values
      with record
         Bool_Value : Boolean;
      end record;
   package bool_io is new text_io.enumeration_io(boolean);

   type Get_Procedure is access procedure (
     File : in text_io.file_type;
     Value : out values'class);

   procedure Default_Get_Procedure(
     File : in text_io.file_type;
     Value : out Bool_Values) is

   begin
     bool_io.get(File, Value.Bool_Value);
   end Default_Get_Procedure;

 Get_Message : Get_Procedure := Default_Get_Procedure'Access; -- what's
wrong?
-- ...
 File : text_io.file_type;
begin
  null;
end test;






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

* Re: Q: Access subprogram with class type parameters
  2000-03-08  0:00 Q: Access subprogram with class type parameters Rush Kester
@ 2000-03-09  0:00 ` Ted Dennison
  0 siblings, 0 replies; 2+ messages in thread
From: Ted Dennison @ 2000-03-09  0:00 UTC (permalink / raw)


In article <38C6F379.173A92AF@jhuapl.edu>,
  Rush Kester <Rush.Kester@jhuapl.edu> wrote:
> This is my first attempt at using subprogram access types and class
> programming.
>
> Why doesn't Default_Get_Procedure match Get_Procedure in the
following?
>

>    type Get_Procedure is access procedure (
>      File : in text_io.file_type;
>      Value : out values'class);
>
>    procedure Default_Get_Procedure(
>      File : in text_io.file_type;
>      Value : out Bool_Values) is

Because Values'Class and Bool_Values aren't the same type. You can't
define a procedure type that will take a procedure with a parameter of a
different type than is in the declaration, even if that different type
does happen to have been derived from the one specified.

I made this exact mistake about 3 months ago when I was trying to write
the parsing support for OpenToken.


--
T.E.D.

http://www.telepath.com/~dennison/Ted/TED.html


Sent via Deja.com http://www.deja.com/
Before you buy.




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

end of thread, other threads:[~2000-03-09  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-08  0:00 Q: Access subprogram with class type parameters Rush Kester
2000-03-09  0:00 ` Ted Dennison

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