Re: Accessing class structure fields outside the class [message #90974 is a reply to message #90973] |
Tue, 19 May 2015 13:28   |
Russell[1]
Messages: 101 Registered: August 2011
|
Senior Member |
|
|
You're making a few mistakes here.
The class prototype (your class1__define), only defines the datatypes of the class fields. So the fact that you use "value:5" is irrelevant, since this procedure simply defines class1 as a named structure that will contain field named "value" which is an integer. Similarly, you have a field named "pointer" which is a pointer data type.
You will need to explicitly initialize the data. In your example this would be:
pro class1__define
foo = {CLASS1, value:0, pointer: ptr_new()}
end
pro main
a={class1,5,ptr_new(4.)}
print, a.value, *a.pointer
end
Hope this helps.
Russell
On Tuesday, May 19, 2015 at 4:12:28 PM UTC-4, evan....@richmond.edu wrote:
> Hello everyone. I would like to access field values in class structures outside their class.
>
> For example:
>
> Pro class1__define
> struct = {class1, value:5, pointer:new_ptr(3)}
> end
>
> Pro main
> a = {class1}
> print, a.value, *a.pointer
> end
>
> This approach 'zeros' the values inside class1's structure and turns any pointers into a null pointer. Is there a way to access the field values in class1's struct outside the class? Among other reasons, I want to accomplish this without having class1's structure be defined in main so that other methods, functions, and procedures can operate on the field values as they change during a calculation
|
|
|