任务定义中的非法声明

Illegal declaration in task definition

我有以下任务说明:

with Ada.Real_Time; use Ada.Real_Time;

package pkg_task is
    task type task_t is
        activationTime : constant Integer := 1;
        period : constant Integer := 2;
        computingTime : constant Integer := 1;
        startingTime : Time;
    end task_t;
end pkg_task;

我在编译时,在任务说明中声明变量的所有行中都出现了标题中提到的错误,我不知道是什么问题。

任务的接口是它的条目,因此您只需在任务规范中声明条目。任务中的任何局部变量都在任务主体的声明部分中声明。

没有任何条目的任务被简单地声明:

task Something;

正如 Jacob 所写,您不能导出任何不是任务条目的内容。 在这种情况下,您的任务非常简单

package pkg_task is
   task type task_t;
end pkg_task;

在正文中,您可以使用变量。

package body pkg_task is

   task body task_t is
      Activation_Time : constant Integer := 1;
      Period          : constant Integer := 2;
      Computing_Time  : constant Integer := 1;
      -- Starting_Time   : Time;
   begin
      null;
   end task_t;
end pkg_task;

无论如何,如果您能向我们解释您要做什么,事情会更容易。