In Ada, I have the following spec file:
GENERIC
TYPE Item IS PRIVATE; --type of array
size : integer; --size of array
PACKAGE gwar IS
function get_size return integer;
END gwar;
And body file:
with Ada.Text_Io;
use Ada.Text_Io;
package body gwar is
--Get_Size allows the txt file to specify how much space to allocate.
function get_size return Integer is
Filename : String := "win.txt";
File : Ada.Text_IO.File_Type;
Line_Count : Integer := 0;
ReturnSize : Integer;
begin
Ada.Text_IO.Open(File => File,
Mode => Ada.Text_IO.In_File,
Name => Filename);
while Line_Count /= 1 loop
declare
Line : String := Ada.Text_IO.Get_Line(File);
begin
ReturnSize := Integer'Value(Line);
Line_Count := 1;
end;
end loop;
Ada.Text_IO.Close (File);
return ReturnSize;
end get_size;
begin
null;
end gear;
What I want to do is set my size
integer to the value returned by get_size
. How can I do this? I have tried putting my function before my size
variable in the spec file, but it expected end of file. I tried setting size : integer := gwar.get_size
, but that does not work either. Is this possible?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…