From: "Alejandro R. Mosteo" <alejandro@mosteo.com>
Subject: Re: Ada 2005 problem using Iterate
Date: Wed, 5 Oct 2016 10:15:02 +0200
Date: 2016-10-05T10:15:02+02:00 [thread overview]
Message-ID: <nt2cpp$bsh$1@dont-email.me> (raw)
In-Reply-To: <cb6a1464-5fd6-4ea7-ad38-153b6ee199ad@googlegroups.com>
On 05/10/16 09:28, Roger wrote:
> 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!
What I see from checking the a-convec.ads spec
procedure Iterate
(Container : Vector;
Process : not null access procedure (Position : Cursor));
is that your Show_Two_Numbers should expect a Cursor and not and index.
I don't see any other iterate with a compatible profile.
HTH,
Alex.
> 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 prev parent reply other threads:[~2016-10-05 8:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-05 7:28 Ada 2005 problem using Iterate Roger
2016-10-05 8:15 ` Alejandro R. Mosteo [this message]
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