1

I have a package called Linked_List(.ads) Here is the code in it:

Generic
   type T is private;
package Linked_List is
   type List is tagged record
       Data : T;
   end record;
end Linked_List;

and here is the code in the package which contains the main function (main.adb)

with Ada.Text_IO; use Ada.Text_IO;
with Linked_List;
procedure Main is
  type ListOfIntegers is new Linked_List(T => Integer);
begin
   null;
end Main;

I'm getting this error:

4:30 subtype mark required in this context 
found "Linked_List" declared at linked_list.ads:3
found "Linked_List" declared at linked_list.ads:3
4:41 incorrect constrain for this kind of type

Any help is appreciated.

Planet_Earth
  • 325
  • 1
  • 3
  • 11

1 Answers1

5

new Linked_List(T => Integer) defines a new package, not a new type. The error messages you’re getting are because the compiler thinks you’re declaring a type, so seeing the name of a package at column 30 confused it; it wanted to see the name of a (sub)type.

Line 4 should read

package ListOfIntegers is new Linked_List(T => Integer);

after which there is a type ListOfIntegers.List, so you can write

My_List : ListOfIntegers.List;

You may find having to say ListOfIntegers. all the time annoying; you can say

use ListOfIntegers;

after which you can just write

My_List : List;

but it’s usually thought best not to overdo this (if you have dozens of “withed” packages, “using” them all makes it difficult to know which one you’re referring to).

By the way, normal Ada usage is to use underscores to separate words in identifiers: List_Of_Names.

Simon Wright
  • 25,108
  • 2
  • 35
  • 62