問題のタスクタイプが差別されていることがわかったので、これは元の回答の書き直しです。
デフォルトなしで「判別式」を介して各タスクに値を渡しているため、タスクの種類が制約されていません。判別式に値を指定せずに型のオブジェクトを宣言することはできません (オブジェクトが作成されると判別式を変更できないため、デフォルトを指定しても役に立ちません)。
これに対する一般的なアプローチの 1 つは、アクセス タイプを使用します。
with Ada.Integer_Text_IO;
with Ada.Text_IO;
procedure Maciek is
task type T (Param : Integer);
type T_P is access T;
type My_Arr is array (Integer range <>) of T_P;
task body T is
begin
Ada.Text_IO.Put_Line ("t" & Param'Img);
end T;
N, M : Integer;
begin
Ada.Text_IO.Put ("number of tasks: ");
Ada.Integer_Text_IO.Get (N);
Ada.Text_IO.Put ("parameter: ");
Ada.Integer_Text_IO.Get (M);
declare
-- Create an array of the required size and populate it with
-- newly allocated T's, each constrained by the input
-- parameter.
Arr : My_Arr (1 .. N) := (others => new T (Param => M));
begin
null;
end;
end Maciek;
new
ed タスクが完了したら、割り当てを解除する必要がある場合があります。上記のコードでは、declare
ブロックの終了時にタスクのメモリがリークされます。