comp.lang.ada
 help / color / mirror / Atom feed
* Problem whith objects, access and abstract tagged private types
@ 2004-01-08 13:58 Bruno
  2004-01-08 14:56 ` Georg Bauhaus
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Bruno @ 2004-01-08 13:58 UTC (permalink / raw)


Hello to all,

I'm newbie in Ada95 and I have some difficulties with the language.
I'll give you my specifications :

Specif (.ads) :
---------------

   package Objets is

      type Item_Type is abstract tagged private;
      -- Action
      procedure Traitement (F : in Item_Type);
      -- Allows init
      procedure Modifier (F  : in out Item_Type'Class;
                          Nb : in     Natural);

      type Item_Elmt is private;
      function To_Item_Elmt (F : in Item_Type'Class) return Item_Elmt;
      function To_Item_Type (F : in Item_Elmt) return Item_Type'Class;

   private

      type Item_Type is abstract tagged
         record
            Compteur : Natural := 0;
         end record;
      type Item_Elmt is access all Item_Type'Class;

   end Objets;

I chose private types for hiding implementation of my types and access
types.

My problem is that I can't make the function "To_Item_Elmt" that create
"Item_Elmt".

I try to write this body :

   function To_Item_Elmt (F : in Item_Type'Class) return Item_Elmt is
      My_Tag : constant Ada.Tags.Tag := F'Tag;
   begin
      return new My_Tag' (F);
   end To_Item_Elmt;

The compilation indicates the following errors :
    subtype mark required in this context
    found "My_Tag" declared at line 30

If somebody could help and explain me how to resolve my problem, thanks for
his help.

Bruno






^ permalink raw reply	[flat|nested] 5+ messages in thread
* RE: Problem whith objects, access and abstract tagged private types
@ 2004-01-08 14:51 amado.alves
  0 siblings, 0 replies; 5+ messages in thread
From: amado.alves @ 2004-01-08 14:51 UTC (permalink / raw)
  To: comp.lang.ada

<<
...
      type Item_Elmt is access all Item_Type'Class;
...
   function To_Item_Elmt (F : in Item_Type'Class) return Item_Elmt is
      My_Tag : constant Ada.Tags.Tag := F'Tag;
   begin
      return new My_Tag' (F);
   end To_Item_Elmt;
>>

According to your own definition of Item_Elmt and To_Item_Elmt you must return an access value, not a Tag. Maybe you want to return an access to F. As it stands, you cannot, because F might be a value. If the actual parameter passed is always a variable then use mode in out for F. The return something along the lines of F'Access.



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

end of thread, other threads:[~2004-01-08 18:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-08 13:58 Problem whith objects, access and abstract tagged private types Bruno
2004-01-08 14:56 ` Georg Bauhaus
2004-01-08 15:22 ` Dmitry A. Kazakov
2004-01-08 18:31 ` Jeffrey Carter
  -- strict thread matches above, loose matches on Subject: below --
2004-01-08 14:51 amado.alves

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