我想重命名 Synchronized_Queue_Interface 入队条目,但不知道如何正确操作。
with Ada.Containers.Synchronized_Queue_Interfaces;
with Ada.Containers.Unbounded_Synchronized_Queues;
package Test is
use Ada.Containers;
package Boolean_Queue_Interfaces is new Synchronized_Queue_Interfaces
(Element_Type => Boolean);
package Boolean_Queues is new Unbounded_Synchronized_Queues
(Queue_Interfaces => Boolean_Queue_Interfaces);
Queue : Boolean_Queues.Queue;
procedure Enqueue (New_Item : Boolean) renames Queue.Enqueue; -- Illegal
end Test;
最佳答案
您需要使用的表格是这样的:
Protected Type Example is
Entry Queue( Item : Integer );
Private
Element : Integer := 0;
End Example;
Protected Body Example is
Entry Queue( Item : Integer ) when true is
Begin
Element:= Item;
End Queue;
End Example;
V : example;
Procedure Q( X : Integer )
renames V.Queue;
这就是您所拥有的,但是编译器似乎无法区分重载的形式(Boolean_Queue_Interfaces.Queue.Enqueue
与 Boolean_Queues.Queue.Enqueue
)。 -- 解决此问题的最佳方法是明确说明:
procedure Do_it( Item : Boolean )
renames Boolean_Queues.Queue(Queue).Enqueue;
您可能应该提交一份错误报告,当然要求更好的错误消息传递。
关于rename - 如何重命名 protected 对象条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69145376/