1
votes

I am receiving a "non-visible declaration" error on my Generator. I am converting this code from a single procedure to using multiple procedures and functions.

I have truncated the code a bit Any explanation of the non-visible declaration error would be appreciated. The non visible declaration error is occurring in this block of code:

WITH Ada.Integer_Text_IO;
USE Ada.Integer_Text_IO;
WITH Ada.Text_IO;
USE Ada.Text_IO;
WITH Ada.Strings;
USE Ada.Strings;
WITH Ada.Numerics.Discrete_Random;

PROCEDURE Project IS
SUBTYPE Guess IS Integer RANGE 1 .. 25;
G             : Generator;
CorrectAnswer : Guess;
UserGuess     : Guess;
BEGIN
Reset (G);    
CorrectAnswer := Random(G);
   FOR I IN 1..3 LOOP          
      GetUserGuess(UserGuess);
      PrintCorrectAns(CorrectAnswer);
      IF IsCorrect(UserGuess) THEN
         Put("You Win!");
      ELSE
         Put("You Lose!");
      END IF;
   END LOOP;
End Project;
1
Read sscce.org, you should create the shortest possible example that reproduces the error. Remove the code that's not relevant to the problem. It still needs to be compilable, though. - sashoalm
Also, can't you copy and paste the actual error text the compiler gave you? - sashoalm
What's going on with the edits here? Please stop all the rollbacks. - Brad Larson

1 Answers

5
votes

The non-visible declaration at a-nudira.ads:48 and 50 (line numbers may vary with compiler release) are because Ada.Numerics.Discrete_Random, see ARM A.5.2(16), is a generic package and needs to be instantiated with whichever discrete type you need.

In your case, I guess that’s Guess:

package RNG is new Ada.Numerics.Discrete_Random (Result_Subtype => Guess);
use RNG;