comp.lang.ada
 help / color / mirror / Atom feed
* premature use
@ 2002-05-05 15:03 Preben Randhol
  2002-05-05 18:20 ` Jim Rogers
  2002-05-06 14:06 ` Stephen Leake
  0 siblings, 2 replies; 4+ messages in thread
From: Preben Randhol @ 2002-05-05 15:03 UTC (permalink / raw)



When I try to make the package as below I get from GNAT the error:

   premature use of private type

I understand this is correct, but is it possible to make this package in
a way that makes the Help_File_Type and Help_Index_Type private while
keeping File_List and Index_List public?

Thanks in advance.

Preben
--------------------------------------------------------------------
with Double_Linked_List;
with Ada.Strings.UnBounded;   use Ada.Strings.UnBounded;

pragma Elaborate_All (Double_Linked_List);

package Help_Lists is

   type Help_File_Type is private;
   type Help_Index_Type is private;

   package File_List is
      new Double_Linked_List (Data_Type => Help_File_Type);

   package Index_List is
      new Double_Linked_List (Data_Type => Help_Index_Type);

private
   type Help_File_Type is
      record
         Topic : Unbounded_String;
         Text  : Unbounded_String;
      end record;

   type Help_Index_Type is
      record
         Section : Unbounded_String;
         List    : File_List.List_Type;
      end record;

   Help_List : Index_List.List_Type := Index_List.New_List;

end Help_Lists;
---------------------------------------------------------------------



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

* Re: premature use
  2002-05-05 15:03 premature use Preben Randhol
@ 2002-05-05 18:20 ` Jim Rogers
  2002-05-06  9:20   ` Preben Randhol
  2002-05-06 14:06 ` Stephen Leake
  1 sibling, 1 reply; 4+ messages in thread
From: Jim Rogers @ 2002-05-05 18:20 UTC (permalink / raw)


Try putting File_List and Index_List in a child package

package Help_Lists.File_Lists is
    package File_List is
       new Double_Linked_List(Data_Type => Help_File_Type);
    pacakge Index_List is new
       Double_Linked_List(Data_Type => Help_Index_Type);
end Help_Lists.File_Lists;

Jim Rogers

Preben Randhol wrote:

> When I try to make the package as below I get from GNAT the error:
> 
>    premature use of private type
> 
> I understand this is correct, but is it possible to make this package in
> a way that makes the Help_File_Type and Help_Index_Type private while
> keeping File_List and Index_List public?
> 
> Thanks in advance.
> 
> Preben
> --------------------------------------------------------------------
> with Double_Linked_List;
> with Ada.Strings.UnBounded;   use Ada.Strings.UnBounded;
> 
> pragma Elaborate_All (Double_Linked_List);
> 
> package Help_Lists is
> 
>    type Help_File_Type is private;
>    type Help_Index_Type is private;
> 
>    package File_List is
>       new Double_Linked_List (Data_Type => Help_File_Type);
> 
>    package Index_List is
>       new Double_Linked_List (Data_Type => Help_Index_Type);
> 
> private
>    type Help_File_Type is
>       record
>          Topic : Unbounded_String;
>          Text  : Unbounded_String;
>       end record;
> 
>    type Help_Index_Type is
>       record
>          Section : Unbounded_String;
>          List    : File_List.List_Type;
>       end record;
> 
>    Help_List : Index_List.List_Type := Index_List.New_List;
> 
> end Help_Lists;
> ---------------------------------------------------------------------
> 




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

* Re: premature use
  2002-05-05 18:20 ` Jim Rogers
@ 2002-05-06  9:20   ` Preben Randhol
  0 siblings, 0 replies; 4+ messages in thread
From: Preben Randhol @ 2002-05-06  9:20 UTC (permalink / raw)


On Sun, 05 May 2002 18:20:11 GMT, Jim Rogers wrote:
> Try putting File_List and Index_List in a child package
> 
> package Help_Lists.File_Lists is
>     package File_List is
>        new Double_Linked_List(Data_Type => Help_File_Type);
>     pacakge Index_List is new
>        Double_Linked_List(Data_Type => Help_Index_Type);
> end Help_Lists.File_Lists;

Won't I get a problem due to:

 
    type Help_Index_Type is
       record
          Section : Unbounded_String;
          List    : File_List.List_Type;
                    ^^^^^^^^^
       -- Would it not become circular dependancies here?


But I'll test it out after work.

Preben
-- 
Preben Randhol ------------------- http://www.pvv.org/~randhol/ --
                 �For me, Ada95 puts back the joy in programming.�



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

* Re: premature use
  2002-05-05 15:03 premature use Preben Randhol
  2002-05-05 18:20 ` Jim Rogers
@ 2002-05-06 14:06 ` Stephen Leake
  1 sibling, 0 replies; 4+ messages in thread
From: Stephen Leake @ 2002-05-06 14:06 UTC (permalink / raw)


Preben Randhol <randhol+abuse@pvv.org> writes:

> When I try to make the package as below I get from GNAT the error:
> 
>    premature use of private type
> 
> I understand this is correct, but is it possible to make this package in
> a way that makes the Help_File_Type and Help_Index_Type private while
> keeping File_List and Index_List public?

Put the Help_index_Type in a grand-child package. This compiles with
GNAT 3.15a on Windows NT:

generic
   type Data_Type is limited private;
package Double_Linked_List is

   type List_Type is new Integer;
end Double_Linked_List;

with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
package Help_Files is

   type Help_File_Type is private;

private
   type Help_File_Type is
      record
         Topic : Unbounded_String;
         Text  : Unbounded_String;
      end record;

end Help_Files;

with Double_Linked_List;
Package Help_Files.Lists is
   package File_List is
      new Double_Linked_List (Data_Type => Help_File_Type);

end Help_Files.Lists;

package Help_Files.Lists.Indexes is

   type Help_Index_Type is private;

private
   type Help_Index_Type is
      record
         Section : Unbounded_String;
         List    : File_List.List_Type;
      end record;

end Help_Files.Lists.Indexes;

package Help_Files.Lists.Indexes.Lists is

   package Index_List is
      new Double_Linked_List (Data_Type => Help_Index_Type);

private
   
--   Help_List : Index_List.List_Type := Index_List.New_List;
   Help_List : Index_List.List_Type := 1;

end Help_Files.Lists.Indexes.Lists;

-- 
-- Stephe



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

end of thread, other threads:[~2002-05-06 14:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-05 15:03 premature use Preben Randhol
2002-05-05 18:20 ` Jim Rogers
2002-05-06  9:20   ` Preben Randhol
2002-05-06 14:06 ` Stephen Leake

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