Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26753 Discussions

Convert array of objects into array of properties

S__MPay
Beginner
123 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
Black Belt
123 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

3 Replies
Arjen_Markus
Valued Contributor III
123 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.

S__MPay
Beginner
123 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)?

IanH
Black Belt
124 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

Reply