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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ab46f8fd8bc30c31,start X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!r33g2000yqn.googlegroups.com!not-for-mail From: "patrick.gunia@googlemail.com" Newsgroups: comp.lang.ada Subject: Problems with Scope of aliased Objects Date: Thu, 16 Apr 2009 06:43:22 -0700 (PDT) Organization: http://groups.google.com Message-ID: NNTP-Posting-Host: 78.34.66.221 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1239889402 24414 127.0.0.1 (16 Apr 2009 13:43:22 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 16 Apr 2009 13:43:22 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: r33g2000yqn.googlegroups.com; posting-host=78.34.66.221; posting-account=D7TrwwoAAAAVyN71CASRiSp392RIjlsB User-Agent: G2/1.0 X-HTTP-UserAgent: Opera/9.64 (Windows NT 6.0; U; de) Presto/2.1.1,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:4493 Date: 2009-04-16T06:43:22-07:00 List-Id: Hi all, I`ve got a question concerning the scope of Ada-variables. I got the following situation: First Approach: - I declare a local variable "A" of type "xy" within the declaration part of a procedure - the variable-members are set and finally put into an array =3D> after leaving the procedure the variables are still accessable through the Array which is defined on a higher scope-level Second Approach: Now I want to restructure my code using general Access-Types for the declared variables. - I declare a variable "refA" as an alias to my variable-type "xy" (also in the declaration-part of the procedure) - I do the same operations on "refA" I did before on "A" - I declare an instance of a general access-type to my variable of type "xy" (also in the declaration-part of the procedure) - I pass the access-type-Instance into the Array =3D> after leaving the function, I get errors during runtime Third Approach: My third approach works, but uses Heap-Memory for "A" thus I generate the instances dynamically within my procedure and then pass the general access-types into my array. Now here=B4s my explanation for this: When leaving the function in my second approach the pointers are still avaiable, because they=B4re passed into the array, but the objects, the pointer point to are not, because they=B4re out of scope and thus destroyed. Is this rigth? Anf if so, what do I have to do, to get my second approach running, and not losing my locally declared objects after leaving the function. The reason why I restructure using access-types is that I want to use the array for keeping instances of different classes within a class hierarchy and thus I have to declare it as an array for general access types to my root-class. Thank you for your help!