comp.lang.ada
 help / color / mirror / Atom feed
From: Martin Dowie <martin.dowie@btopenworld.com>
Subject: Re: Inter-object pointer problem
Date: Tue, 16 May 2006 21:27:39 +0100
Date: 2006-05-16T21:27:39+01:00	[thread overview]
Message-ID: <R_ednV-7MrAgqPfZnZ2dnUVZ8s6dnZ2d@bt.com> (raw)
In-Reply-To: <1147806613.377038.169250@j33g2000cwa.googlegroups.com>

Alex Catlin wrote:
> Say I have Packages A and B, implementing data structure A and B
> respectively. I want to create a new B everytime I call a certain
> procedure, and insert a pointer to that data structure into the main
> data structure A to keep track of all these B's flying around.
> 
> I'm trying something like:
> 
> with A_Pkg, B_Pkg;
> .....
> package A_Structure is new A_Pkg (B_Pointer_Type);
> B_List : A_Structure;
> 
> procedure X (Data : in Data_Type) is
>     package B_Structure is new B_Pkg;
>     New_B : B_Structure
>     Ptr_B is access New_B;
> begin
>     B_Structure.Insert(B_Structure,Data);
>     B_List.Insert(B_List,Ptr_B);
> end X;
> .....
> 
> The problem is that generic package A is expecting to be instantiated
> with an access type, but the Ptr_B doesnt exist until I have called
> procedure X. If this were C I would instantiate A_Structure as a static
> type during procedure X so it didn't keep making new A's every call,
> but I dont think I can do that in ADA. Is there a fix based on some
> concept i'm completely missing or am I going to have to completely
> change the organisation of the program?
> I'd be grateful if anyone could point me in the direction of something
> to try, Thanks.
> 

If you want to have a container holding lots of "B"'s and call that 
container an "A" then try the new Ada.Container.* hierarchy in Ada2005 
(there are 'backports' to Ada95 out there if you have even a gentle look).

Only you wouldn't be inserting a pointer to a "B" in the structure "A" 
but an "Iterator".

Cheers
-- Martin

p.s. As other have pointed out, your example highlights some serious 
misconception about Ada - but at least Ada is fun to learn! :-)



      parent reply	other threads:[~2006-05-16 20:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1147806613.377038.169250@j33g2000cwa.googlegroups.com>
2006-05-16 19:58 ` Inter-object pointer problem Georg Bauhaus
2006-05-16 20:09 ` Jeffrey R. Carter
     [not found]   ` <1147816421.575165.66310@j33g2000cwa.googlegroups.com>
2006-05-17  2:03     ` Jeffrey R. Carter
2006-05-16 20:27 ` Martin Dowie [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox