comp.lang.ada
 help / color / mirror / Atom feed
From: "patrick.gunia@googlemail.com" <patrick.gunia@googlemail.com>
Subject: Problems with Scope of aliased Objects
Date: Thu, 16 Apr 2009 06:43:22 -0700 (PDT)
Date: 2009-04-16T06:43:22-07:00	[thread overview]
Message-ID: <e9b734e0-478a-4849-b821-444cdbdfac2a@r33g2000yqn.googlegroups.com> (raw)

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
=> 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
=> 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´s my explanation for this:
When leaving the function in my second approach the pointers are still
avaiable, because they´re passed into the array, but the objects, the
pointer point to are not, because they´re 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!



             reply	other threads:[~2009-04-16 13:43 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-16 13:43 patrick.gunia [this message]
2009-04-16 15:29 ` Problems with Scope of aliased Objects Adam Beneschan
2009-04-16 15:59   ` patrick.gunia
2009-04-16 16:26     ` Adam Beneschan
2009-04-16 16:37       ` patrick.gunia
2009-04-16 20:11       ` Adam Beneschan
2009-04-16 15:47 ` Dmitry A. Kazakov
2009-04-16 19:12   ` sjw
2009-04-16 15:50 ` Ludovic Brenta
2009-04-16 16:01   ` Adam Beneschan
2009-04-16 16:12     ` patrick.gunia
2009-04-17 13:53       ` Alex 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