From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5524603d74cda791 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.bt.com!news.bt.com.POSTED!not-for-mail NNTP-Posting-Date: Tue, 16 May 2006 15:27:40 -0500 Date: Tue, 16 May 2006 21:27:39 +0100 From: Martin Dowie User-Agent: Thunderbird 1.5.0.2 (Windows/20060308) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Inter-object pointer problem References: <1147806613.377038.169250@j33g2000cwa.googlegroups.com> In-Reply-To: <1147806613.377038.169250@j33g2000cwa.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 81.153.247.10 X-AuthenticatedUsername: NoAuthUser X-Trace: sv3-VL8344U/X3F76Qkua+SNeKRj1dwM+4/h8R8ZHw9ZSP7KefkIkaAyltWYGySfmRmulZFrBDU5iK7gK0K!YIgxWt3KSatCd00PfmuPJ8jExaqvQiAfPKLbR/4bPJzJAlejsBEXtpdZn4BkFS2RBAl+qDIxT3U= X-Complaints-To: abuse@btinternet.com X-DMCA-Complaints-To: abuse@btinternet.com X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news2.google.com comp.lang.ada:4279 Date: 2006-05-16T21:27:39+01:00 List-Id: 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! :-)