Domanda

I'm learning Ada and am using the book Rendez-vous with Ada by Naiditch (1995). On page 385, an example is given for package specification file with an incomplete type declaration:

package Restaurant_Linked_List is

   subtype Name_Type is String (1..20);
   type Restaurant_Record is private;

   procedure Add_To_List (New_Entry: in Restaurant_Record);
   procedure Get (New_Restaurant: out Restaurant_Record);
   procedure Delete_From_List (Target: in Name_Type);
   procedure Search_List (Target: in Name_Type);
   procedure Output_List;

   private
      type Ethnicity is (Chinese, Japanese, French, Korean, Mexican, Italian, Jewish, American, German);
      subtype Price_Type is Float range 0.0 .. 150.0;
      type Restaurant_Record; -- incomplete type declaration
      type Restaurant_Pointer is access Restaurant_Record;
      type Restaurant_Record is -- complete type declaration
        record
           Name: Name_Type;
           Food: Ethnicity;
           Average_Price: Price_Type;
           Next: Restaurant_Pointer;
        end record;

end Restaurant_Linked_List; 

However on compilation of this primary unit even with the -gnat95 switch, I get the error message:

15:11 invalid completion of private type "Restaurant_Record" defined at line 4

where line 15 is the line: type Restaurant_Record; -- incomplete type declaration.

Naiditch proposed the above workaround to have the pointer (Restaurant_Pointer) to be a component of the very type of object that it can point to as written on page 384 in the book.

So how to fix the above code?

Thank you.

È stato utile?

Soluzione

The declaration at line 4 is already enough to allow you to declare Restaurant_Pointer. So just delete line 15.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top