title: Fortran 2008 - array variable in class
body: <p>I have a following class, where I need to store objects of type <code>neuron_t</code> and <code>connection_t</code>.</p>
  <pre><code>!&gt; Class representing a general network
  type :: net_t
      private
  
      character(:), allocatable                 :: net_type              !&lt; Type of the net
      integer(kind=integer_4neuro)              :: num_of_neurons        !&lt; Number of neurons in the net
      character(:), allocatable                 :: training_method       !&lt; Used training method
  
      class(neuron_t), allocatable              :: neuron_arr(:)         !&lt; Array containing all neurons
      integer(kind=integer_4neuro), allocatable :: input_neuron_arr(:)   !&lt; Array of input neuron indices
      integer(kind=integer_4neuro), allocatable :: output_neuron_arr(:)  !&lt; Array of output neuron indices
      class(connection_t), allocatable          :: connection_arr(:)     !&lt; Array of all connections
  
  contains
      !&gt; Prints information about the network to the standard output.
      procedure :: print_info =&gt; print_info_impl
  
      !&gt; Saves the network instance to the Fortran binary file
      procedure :: save_net_bin =&gt; save_net_bin_impl
  
  end type net_t
  
  interface net_t
      !&gt; Constructor of net_t class
      !! Loads complete info about network from file
      !! @param[in] filepath Path to the file with network configuration
      !! @return Returns pointer to the new instance of the class net_t
      module procedure :: new_net_1
  end interface net_t
  </code></pre>
  <p>I tried to initialize the array like this</p>
  <pre><code>    allocate(new_obj)
  
      ! Init object
      do i=1,5
          new_obj%neuron_arr(i) =  mock_neuron_t()
      end do
  </code></pre>
  <p>but I'm getting the following error:</p>
  <pre><code>         new_obj%neuron_arr(i) =  mock_neuron_t()
          1
  Error: Nonallocatable variable must not be polymorphic in intrinsic assignment at (1) - check that there is a matching specific subroutine for '=' operator
  </code></pre>
  <p>Do you know, what am I doing wrong? <code>mock_neuron_t</code> extends type <code>neuron_t</code>, so it should be ok.</p>
  <h3>EDIT:</h3>
  <p>Both <code>neuron_t</code> and <code>connection_t</code> classes are abstract, so I'm getting following error now after adding <code>allocate(new_obj%neuron_arr)</code>:</p>
  <pre><code>     allocate(new_obj%neuron_arr)
               1
  Error: Allocating new_obj of ABSTRACT base type at (1) requires a type-spec or source-expr
  
           new_obj%neuron_arr(i) =  mock_neuron_t()
          1
  Error: Nonallocatable variable must not be polymorphic in intrinsic assignment at (1) - check that there is a matching specific subroutine for '=' operator
  </code></pre>