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

Store array of various classes

Andrew_Smith
Valued Contributor I
723 Views
I currently have an array of bearings with an integer enumerator to tell me what type of bearing they are. I want to use inheritance using subclasses for the bearing types. How can I continue to store an array of these mixed types of bearings?

This code is inteded to define the array someBearings:

type Bearing
real :: contactAngle
end type

type, extends(Bearing) :: BallBearing
real ballDiameter
end type

type, extends(Bearing) :: RollerBearing
real rollerCrownRadius
end type

type BearingPointer
class(Bearing), pointer :: item => null()
end type

type(BearingPointer), allocatable :: someBearings(:)

The code fails on the class component.
0 Kudos
2 Replies
Steven_L_Intel1
Employee
723 Views
Are you using the 11.1 compiler? That's the first to accept CLASS. I compiled your excerpt with 11.1.035 and it compiled ok.
0 Kudos
Andrew_Smith
Valued Contributor I
723 Views
Are you using the 11.1 compiler? That's the first to accept CLASS. I compiled your excerpt with 11.1.035 and it compiled ok.

Woops, no I was using 11.0. Getting too far ahead for 11.0. I will give 11.1 a try soon.
0 Kudos
Reply