Re: Pointer and structure question [message #81724] |
Sat, 13 October 2012 19:58 |
timmyb89
Messages: 4 Registered: October 2012
|
Junior Member |
|
|
Thanks, too easy.
On Saturday, October 13, 2012 10:20:36 PM UTC+11, TimB wrote:
> I'm having trouble accessing a structure referred to by a pointer. Here's a simplified example of what I want to do.
>
>
>
> array=replicate(ptr_new(/ALLOCATE_HEAP),2)
>
> *array[0]={var1:1.0,var2:2.0}
>
>
>
> x=*array[0]
>
> print,x.var1
>
> print,*array[0].var1
>
>
>
>
>
> print,x.var1 works, print,*array[0].var1 gives the error "Expression must be a structure in this context: ARRAY.". I need to be able to access var1 without creating the x variable as seen in this example. What am I doing wrong?
>
>
>
> Thanks, Tim
|
|
|
Re: Pointer and structure question [message #81727 is a reply to message #81724] |
Sat, 13 October 2012 04:30  |
Lajos Foldy
Messages: 176 Registered: December 2011
|
Senior Member |
|
|
On Saturday, October 13, 2012 1:20:36 PM UTC+2, TimB wrote:
> I'm having trouble accessing a structure referred to by a pointer. Here's a simplified example of what I want to do.
>
>
>
> array=replicate(ptr_new(/ALLOCATE_HEAP),2)
>
> *array[0]={var1:1.0,var2:2.0}
>
>
>
> x=*array[0]
>
> print,x.var1
>
> print,*array[0].var1
>
>
>
>
>
> print,x.var1 works, print,*array[0].var1 gives the error "Expression must be a structure in this context: ARRAY.". I need to be able to access var1 without creating the x variable as seen in this example. What am I doing wrong?
>
>
>
> Thanks, Tim
Operator precedence. Use parenthesis when in doubt.
IDL> print,(*array[0]).var1
1.00000
regards,
Lajos
|
|
|
|