免费Pascal编译器 - 致命:语法错误,“OF”预期但“[”发现......?

问题描述 投票:0回答:1

我在这里定义了这个程序

Player 
is a user-defined record.Here is the procedure:
procedure print_scores(players : array[1..2] of Player);
begin
    writeln;
    writeln(' Player 1 (', players[1].player_name.firstname, ' ',players[1].player_name.lastname, ') |=| ', players[1].score);
    writeln(' Player 2 (', players[2].player_name.firstname, ' ',players[2].player_name.lastname, ') |=| ', players[2].score);
    writeln;
end;

但我得到这个错误:

main.pas(9,39)致命:语法错误,“OF”预期但“[”找到

我检查了一下

procedure print_scores(players : array[1..2] of Player);

是第9行。

pascal freepascal
1个回答
2
投票

您无法在过程参数列表中定义数组类型。它必须单独定义。

type
  TPlayers = array[1..2] of TPlayer;

程序是:

procedure print_scores(const Players: TPlayers);
© www.soinside.com 2019 - 2024. All rights reserved.