John的“Ada 2012编程”第53页分享了一个我无法工作的不完整的代码片段。
我想出了一个完整的程序来扩展书中的代码.
with Ada.Numerics; use Ada.Numerics;
with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
type Coin is (Heads, Tails);
package Random_Coin is new Discrete_Random(Coin);
use Random_Coin;
G : Generator;
C : Coin;
begin
for i in 1 .. 20 loop
C := Random(G);
Put (C'Image);
end loop;
end Main;我使用的"GPS“IDE抱怨了以下错误:
IDE确实给了我"intellisense“(使用Visual中的一个术语),它表明Discrete_Random实际上是可见的,并且是可用的,因为我添加了"with”和" use“语句。
有人能帮我看看我犯的这些愚蠢的错误吗?
发布于 2019-09-03 20:38:42
问题在于,与Ada.Numerics.Pi不同,Pi是Ada.Numerics的一个组件,Discrete_Random是Ada.Numerics的子代。
一旦您说了use Ada.Numerics,您就可以在您的程序中只编写Pi,但是您必须实际使用with Ada.Numerics.Discrete_Random才能使它可用。
实际上,您不需要使用with或use Ada.Numerics,这很好:
with Ada.Numerics.Discrete_Random;
with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
type Coin is (Heads, Tails);
package Random_Coin is new Ada.Numerics.Discrete_Random(Coin);https://stackoverflow.com/questions/57776932
复制相似问题