首页 文章

如何在Ada中将包作为通用参数?

提问于
浏览
2

我想知道将包传递给泛型函数的语法是什么 . 我已经尝试了几种方法但没有成功 .

例如:

generic
    with package <<SomeThing>> is <>;
    procedure forEach(g: in <<MyType>>);

要么

generic
    with package <<SomeThing>>;
    procedure forEach(g: in <<MyType>>);

要么

generic
    package <<SomeThing>>;
    procedure forEach(g: in <<MyType>>);

1 回答

  • 6

    包必须是通用包的实例(否则编译器不会对包有任何了解) . 语法是:

    generic
       with package Foo is new Bar (<>);
    procedure Foreach (G : Foo.T);
    

    有关正式软件包(ARM 12.7),请参阅参考手册部分末尾的Ada Wikibook和示例 .

相关问题