comp.lang.ada
 help / color / mirror / Atom feed
* Problems with Scope of aliased Objects
@ 2009-04-16 13:43 patrick.gunia
  2009-04-16 15:29 ` Adam Beneschan
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: patrick.gunia @ 2009-04-16 13:43 UTC (permalink / 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!



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2009-04-17 13:53 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-16 13:43 Problems with Scope of aliased Objects patrick.gunia
2009-04-16 15:29 ` 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

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