Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
68 Views

Error #8346: A function reference cannot be used as the leftmost part-ref of structure component.

Jump to solution

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?

 

0 Kudos

Accepted Solutions
Highlighted
Valued Contributor III
68 Views

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.

View solution in original post

0 Kudos
6 Replies
Highlighted
Valued Contributor III
69 Views

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.

View solution in original post

0 Kudos
Highlighted
68 Views

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

0 Kudos
Highlighted
Black Belt Retired Employee
68 Views

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.

0 Kudos
Highlighted
Beginner
68 Views

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.

0 Kudos
Highlighted
68 Views

Steve,

Shouldn't the additional ()'s (suggestion 1) have produced an object reference?

Jim Dempsey

0 Kudos
Highlighted
Black Belt Retired Employee
68 Views

jimdempseyatthecove wrote:
Shouldn't the additional ()'s (suggestion 1) have produced an object reference?=

No, that makes an expression.

0 Kudos