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

Convert array of objects into array of properties

S__MPay
Beginner
198 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
198 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
Honored Contributor I
199 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
199 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
199 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.

Reply