Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28381 Discussions

Convert array of objects into array of properties

S__MPay
Beginner
447 Views

Say I have an array of class People called Employees,

ArrayOfEmployedAtAge  = Employees(:)%BirthDate - ArrayOfEmployedDate

The result is

error #6159: A component cannot be an array if the encompassing structure is an array.


 

0 Kudos
1 Solution
IanH
Honored Contributor II
447 Views

Is the BirthDate component a non-allocatable, non-pointer, integer scalar?  If so... Employees%BirthDate will be an integer array (the (:) bit is frippery in this context).  If not... it will be something else, possibly an error.

As per #2... please show the declarations.

View solution in original post

0 Kudos
3 Replies
Arjen_Markus
Honored Contributor I
448 Views

You are not clear about:

  • The question you want an answer to (I guess it is: how to solve the compile error, but then we need information on what you actually want to do)
  • The declaration of the various variables. I guess from the error message that BirthDate, the one component in this statement, is not a scalar, but given the missing declarations, it is no more than a guess

Please provide the missing information, so we can help.

0 Kudos
S__MPay
Beginner
448 Views

Arjen Markus wrote:

You are not clear about:

  • The question you want an answer to (I guess it is: how to solve the compile error, but then we need information on what you actually want to do)
  • The declaration of the various variables. I guess from the error message that BirthDate, the one component in this statement, is not a scalar, but given the missing declarations, it is no more than a guess

Please provide the missing information, so we can help.

I want to make a integer array from the birth date of employees. But Employees is an array of objects and the birth date is only a property. 

Question: Is there a syntax error in this line?

ArrayOfEmployedAtAge  = Employees(:)%BirthDate - ArrayOfEmployedDate

Will Employees(:)%BirthDate return an integer array of BirthDates?

If not what is the right way of doing that (without making a loop)?

0 Kudos
IanH
Honored Contributor II
448 Views

Is the BirthDate component a non-allocatable, non-pointer, integer scalar?  If so... Employees%BirthDate will be an integer array (the (:) bit is frippery in this context).  If not... it will be something else, possibly an error.

As per #2... please show the declarations.

0 Kudos
Reply