- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have made a class named shape which has an array field from class segment. Also there is a class vector.
So I can use my_element%segments(1)%make_vector() to return a vector object.
So far so good by if I use:
print*, my_shape%segments(1)%make_vector().length()
I will get this error
#8346: A function reference cannot be used as the leftmost part-ref of structure component.
To me that statement makes sense so, why compiler is not happy?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You will have to do something along the following lines to get it to work:
asc: associate( vector => my_shape%segments(1)%make_vector() ) print*, vector%length() end associate asc
where the returned object from the make_vector function is "pointed" to something within the ASSOCIATE construct which allows referencing of members within it.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You will have to do something along the following lines to get it to work:
asc: associate( vector => my_shape%segments(1)%make_vector() ) print*, vector%length() end associate asc
where the returned object from the make_vector function is "pointed" to something within the ASSOCIATE construct which allows referencing of members within it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I haven't tried this:
print*, (my_shape%segments(1)%make_vector())%length()
If that works, try
print*, my_shape%segments(1)%make_vector()%length() ! change . to %
Long, long ago I've experienced issues with the compiler confusing what it should do with the non-standard "." member indicate. I don't think this is the case anymore as in the former case it was a misinterpretation as to if a operator followed the . (.eq., .yourOperator., ...)
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ignoring the dot vs. percent syntax, the language doesn't allow you to reference a component of a function reference - it has to be a "data object" (constant, variable, or subobject of a constant). FortranFan has one workaround.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Implementing associate construct as a workaround worked just fine.
This is not a . or % issue as Steve mentioned.
Actually using dot in the forum post was a typo and produces different compiler errors.
Also using
jimdempseyatthecove wrote:
print*, (my_shape%segments(1)%make_vector())%length()
Produces:
error #5082: Syntax error, found '%' when expecting one of: .EQV. .NEQV. .XOR. .OR. .AND. .LT. < .LE. <= .EQ. == .NE. /= .GT. > ... error #6385: The highest data type rank permitted is INTEGER(KIND=8). error #6532: The percent character (%) has been used incorrectly. [LENGTH] error #6355: This binary operation is invalid for this data type.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve,
Shouldn't the additional ()'s (suggestion 1) have produced an object reference?
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
jimdempseyatthecove wrote:
Shouldn't the additional ()'s (suggestion 1) have produced an object reference?=
No, that makes an expression.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page