에이다, 나는 다음과 같은 사양 파일이 있습니다변수 초기화
GENERIC
TYPE Item IS PRIVATE; --type of array
size : integer; --size of array
PACKAGE gwar IS
function get_size return integer;
END gwar;
그리고 몸 파일 :
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;
내가 설정하고 싶은 내 size
get_size
에 의해 반환 된 값의 정수. 어떻게해야합니까? spec 파일에 내 size
변수 앞에 내 함수를 넣으려고했으나 파일 끝이 예상됩니다. size : integer := gwar.get_size
설정을 시도했지만 작동하지 않습니다. 이것이 가능한가?
크기 var는 제네릭 사양의 일부입니다. 일반 사양 외부로 이동하고 일반을 인스턴스화 한 다음 get_size 함수를 호출해야합니다. – NWS
'in out' 모드의 일반적인 공식'size'를 만들 수 있습니다 - [ARM 12.4] (http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-12-4.html) –