Quantcast
Channel: Intel® Software - Intel® Fortran Compiler for Linux* and macOS*
Viewing all articles
Browse latest Browse all 2746

Assignment error OOP and polymorphism

$
0
0

Hi all. Trying OOP and polymorphism I manage to code an example which runs properly in Windows with the ifort14 compiler. When trying to run this in a Linux system with ifort18 I receive the following run-time error message:

"forrtl: severe (189): LHS and RHS of an assignment statement have incompatible types", in line "stringer = CompositeHatSection()"

Any clue? Many thanks in advance  

Gustavo

------------------

 

program zz_demo_polymorphism
    
    type :: CompositeStringerSection
        real :: A   ! area
    end type
    
    type, extends(CompositeStringerSection) :: CompositeHatSection
        real :: H   ! height
    end type
    interface CompositeHatSection
        procedure composite_hat_section_constructor
    end interface
    
    type(CompositeStringerSection) :: stringer
    
    stringer = CompositeHatSection()
    
    print *, 'A = ', stringer%A
    print '(A)', 'Execution finished. Press Enter to continue...'
    read (*,*)
   
contains
    
    function composite_hat_section_constructor() result(this)
    
        ! polymorphic return value (derived class constructor)
        class(CompositeStringerSection), allocatable :: this    
        ! Warning : return value is a general composite stringer
                      
        ! Aux polymorphic variable to adjust derived class constructor
        class(CompositeHatSection), allocatable :: self         
       
        allocate(self)  
        self%A = 100.
        self%H = 25.

        call move_alloc(self, this)
                
    end function

end program

 


Viewing all articles
Browse latest Browse all 2746


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>