comp.lang.ada
 help / color / mirror / Atom feed
* Confused about class-wide types
@ 2016-03-20 11:15 Mart van de Wege
  2016-03-20 12:29 ` Dmitry A. Kazakov
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Mart van de Wege @ 2016-03-20 11:15 UTC (permalink / raw)


Hi,

I'm finding myself a little confused about the interaction between
class-wide types.

Here's some example code:

Spec:

with Ada.Containers.Vectors;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
package Types_Test is
   type Event is abstract tagged null record;
   type Event_Ptr is access Event'Class;
   type Message_Event is new Event with private;
   type Message_Event_Ptr is access Message_Event'Class;
   procedure Message (M : in out Message_Event_Ptr;
		      Mess : in String);
   package Events is new Ada.Containers.Vectors ( Index_Type => Natural,
						 Element_Type => Event_Ptr);
private
   type Message_Event is new Event with record
      Message : Unbounded_String;
   end record;
end Types_Test;

Test program:

with Types_Test; use Types_Test;
procedure Test_Type
is
   M : Message_Event_Ptr;
   Log : Events.Vector;
begin
   M := new Message_Event;
   Message(M,"Test Message");
   Log.Append(M);
end Test_Type;

The idea is that Events.Vector should be able to hold different types of
Events. Yet if I compile it this way, GNAT bombs out with:

test_type.adb:9:15: expected type "Event_Ptr" defined at types_test.ads:5
test_type.adb:9:15: found type "Message_Event_Ptr" defined at types_test.ads:7

Obviously, I'm doing something wrong; I'm probably misunderstanding
something, but what?

-- 
"We will need a longer wall when the revolution comes."
    --- AJS, quoting an uncertain source.

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

end of thread, other threads:[~2016-03-21 21:54 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-20 11:15 Confused about class-wide types Mart van de Wege
2016-03-20 12:29 ` Dmitry A. Kazakov
2016-03-20 13:58   ` Mart van de Wege
2016-03-20 14:26     ` Dmitry A. Kazakov
2016-03-20 12:46 ` Simon Wright
2016-03-20 14:01   ` Mart van de Wege
2016-03-20 13:18 ` Shark8
2016-03-20 13:56   ` Mart van de Wege
2016-03-21 21:54   ` Randy Brukardt

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