【问题标题】:Ada: Access types and invalid completion with recordsAda:访问类型和记录的无效完成
【发布时间】:2014-02-01 02:29:26
【问题描述】:

我正在学习 Ada 并且正在使用这本书 Rendez-vous with Ada by Naiditch (1995)。在页面385 上,给出了类型声明不完整的包规范文件的示例:

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; 

但是,即使使用-gnat95 开关,在编译这个主要单元时,我也会收到错误消息:

15:11 第 4 行定义的私有类型“Restaurant_Record”无效完成

其中第 15 行是该行:输入 Restaurant_Record; -- 不完整的类型声明。

Naiditch 提出了上述解决方法,让指针 (Restaurant_Pointer) 成为它可以指向的对象类型的一个组件,如书中 384 页所写。

那么如何修复上面的代码呢?

谢谢。

【问题讨论】:

    标签: declaration record ada


    【解决方案1】:

    第 4 行的声明已经足以让您声明Restaurant_Pointer。所以只需删除第 15 行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-13
      • 2016-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多