Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
12 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
12 Views

You will have to something

Jump to solution

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
13 Views

You will have to something

Jump to solution

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
12 Views

I haven't tried this:

Jump to solution

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
12 Views

Ignoring the dot vs. percent

Jump to solution

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.

--
Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos
Highlighted
Beginner
12 Views

Implementing associate

Jump to solution

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
12 Views

Steve,

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

Jim Dempsey

0 Kudos
Highlighted
Black Belt Retired Employee
12 Views

Quote:jimdempseyatthecove

Jump to solution

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

No, that makes an expression.

--
Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos