首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ada中对象的Synchronous_Fifo

Ada中对象的Synchronous_Fifo
EN

Stack Overflow用户
提问于 2015-05-15 21:04:56
回答 1查看 167关注 0票数 0

我在Ada中创建了记录,后来又从这些记录中创建了Synchronous_Fifo

代码语言:javascript
复制
type Basic_Record is record
  Argument_1: Integer;
  Operator: Character;
  Argument_2: Integer;
  Product: Integer;
end record;

package Tasks_Fifo is new Synchronous_Fifo(Basic_Record);
use Tasks_Fifo;
Buffer : Fifo;

而且这个运行得很好。后来,我想在对象之外做同样的Synchronous_Fifo

代码语言:javascript
复制
package Adding_Machine is
  protected type Add_Machine is
     entry Store_Record(Task_Record: Basic_Record);
     entry Push_Button;
     entry Get_Product(Product: out Integer);
  private
     My_Record : Basic_Record;
     My_Product: Integer;
  end Add_Machine;
end Adding_Machine;

use Adding_Machine;

package Object_Fifo is new Synchronous_Fifo(Add_Machine);
use Object_Fifo;
Buffer: Fifo;

结果我得到了几个错误:

代码语言:javascript
复制
Multiple markers at this line
- Occurrence of package
- actual for non-limited "Element_Type" cannot be a limited type
- instantiation abandoned

在队列中,我在这里创建Object_Fifo

我应该如何创建这个Fifo?或者可能是Adding_Machine包出了问题

EN

回答 1

Stack Overflow用户

发布于 2015-05-17 03:33:12

下面显示的是package Synchronous_Fifo

代码语言:javascript
复制
generic
     type Element_Type is private;
package Synchronous_Fifo is
  protected type Fifo is
    entry Push(Item : Element_Type);
    entry Pop(Item : out Element_Type);
  private
    Value : Element_Type;
    Is_New : Boolean := False;
  end Fifo;
end Synchronous_Fifo;

package body Synchronous_Fifo is

 ----------
 -- Fifo --
 ----------

 protected body Fifo is

  ---------
  -- Push --
  ---------

  entry Push (Item : Element_Type) when not Is_New is
  begin
     Value := Item;
     Is_New := True;
  end Push;

  ---------
  -- Pop --
  ---------

  entry Pop (Item : out Element_Type) when Is_New is
  begin
     Item := Value;
     Is_New := False;
  end Pop;

 end Fifo;

end Synchronous_Fifo;

我创建了对Adding_Machine的访问,后来又通过这些访问创建了先进先出。

代码语言:javascript
复制
type Adding_Machine_Access is access Adding_Machine;

package Adding_Machines_Fifo is new Synchronous_Fifo(adding_Machine_Access);
use Tasks_Fifo;
Adding_Machines_Fifo : Fifo;

应该能行得通。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30260297

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档