comp.lang.ada
 help / color / mirror / Atom feed
From: Mart van de Wege <mvdwege@gmail.com>
Subject: Confused about class-wide types
Date: Sun, 20 Mar 2016 12:15:58 +0100
Date: 2016-03-20T12:15:58+01:00	[thread overview]
Message-ID: <86oaa97635.fsf@gaheris.avalon.lan> (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.

             reply	other threads:[~2016-03-20 11:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-20 11:15 Mart van de Wege [this message]
2016-03-20 12:29 ` Confused about class-wide types 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
replies disabled

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