维基副本镜像

这是 pascal.chat 维基的镜像。编辑、历史记录和登录都在那里。

Basic Pascal Tutorial/Chapter 4/Forward Referencing/zh CN

English · Français · Български · 中文(中国) · 日本語

4F - 前向引用 (原作者: Tao Yue, 状态: 未更改)

这些虽然容易理解,但有时也让人困惑。

程序中只能使用已经定义的过程/函数?或许是这样吧,先定义后使用。

不过,也有例外,你想先使用后定义?要解决这类问题,你需要使用前向引用。(在预先声明的过程/函数后加forward)

如:

pascal
procedure Later (????????????); forward;

procedure Sooner (????????????);
begin
  ...
  Later (????????????);
end;
...
procedure Later;
begin
  ...
  Sooner (????????????);
end;

示例:

pascal
program q;

procedure a;forward;

procedure b;
begin
    writeln('B调取A:');
    a;
end;

procedure a;
begin
    writeln('A过程.');
end;

begin
    b;
end.

相关

维基百科前向声明

上一页 目录 下一页

From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 4/Forward Referencing/zh CN", as it stood on 2022-08-20 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

版本1,最后由WikiArchive于修改。