From: Roger <rogermc@grapevine.com.au>
Subject: Ada 2005 problem using Iterate
Date: Wed, 5 Oct 2016 00:28:24 -0700 (PDT)
Date: 2016-10-05T00:28:24-07:00 [thread overview]
Message-ID: <cb6a1464-5fd6-4ea7-ad38-153b6ee199ad@googlegroups.com> (raw)
I've successfully used Iterate quite often before but the attached code won't work and I can't figure out why.
Presumably something obvious that I'm blind to!
No matter what I try, compiling numbers.adb produces the error messages:
numbers.adb:24:48: expected access to subprogram "Ada.Containers.Vectors." from instance at numbers.ads:17
numbers.adb:24:48: found type access to procedure "Show_Two_Numbers" defined at line 24
numbers.ads:17 is:
package pNumbers_Vector is new Ada.Containers.Vectors (tNumbers_Index, tNumbers);
numbers.adb:24 is:
Numbers_Vector.Iterate(Show_Two_Numbers'Access);
Can someone tell me what I'm doing wrong?
Regards,
Roger
Numbers.ads:
with Ada.Containers.Vectors;
package Numbers is
type tNumbers_Vector is private;
procedure Print_Numbers_Data (Numbers_Vector : tNumbers_Vector);
private
type tNumbers is record
n1 : Integer := 0;
n2 : Integer := 0;
end record;
subtype tNumbers_Index is Natural;
package pNumbers_Vector is new Ada.Containers.Vectors (tNumbers_Index, tNumbers);
type tNumbers_Vector is new pNumbers_Vector.Vector with null record;
end Numbers;
============================================================
Numbers.adb:
with Ada.Text_IO; use Ada.Text_IO;
package body Numbers is
Numbers_List : tNumbers_Vector;
function New_Record(n1 : Integer; n2 : Integer) return tnumbers is
theRecord : tnumbers := (n1, n2);
begin
return theRecord;
end New_Record;
-- ----------------------------------------------------------------------------------------------------
procedure Print_Numbers_Data (Numbers_Vector : tNumbers_Vector) is
procedure Show_Two_Numbers(Number_Index : tNumbers_Index) is
aNumber_Record : tnumbers;
begin
aNumber_Record := Numbers_Vector.Element(Number_Index);
Put("Number 1: " & Integer'image(aNumber_Record.n1));
Put_Line(" Number 2: " & Integer'image(aNumber_Record.n2));
end Show_Two_Numbers;
begin
Numbers_Vector.Iterate(Show_Two_Numbers'Access);
end Print_Numbers_Data;
-- ----------------------------------------------------------------------------------------------------
begin
for index in Natural range 0..3 loop
Numbers_List.Append(New_Record(index + 2, 2* index + 1));
end loop;
end Numbers;
next reply other threads:[~2016-10-05 7:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-05 7:28 Roger [this message]
2016-10-05 8:15 ` Ada 2005 problem using Iterate Alejandro R. Mosteo
2016-10-05 23:27 ` Roger
2016-10-06 7:24 ` Alejandro R. Mosteo
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox