title: MATLAB - ENUM - Cannot call the constructor of 'X' outside of its enumeration block
body: <p>I am trying to create an enum just like this:</p>
  
  <pre><code>classdef MoleculeType &lt; media.Molecule
      enumeration
          O2 (media.ElementalComposition(media.Atom(media.AtomicWeight.Oxygen), int32(2)))
      end
  
  end
  </code></pre>
  
  <p>Inherited Molecule Class:</p>
  
  <pre><code>classdef Molecule &lt; handle
  
      properties(SetAccess = immutable)
  
          chemicalComposition
  
      end
  
      ...
  
      methods
  
          function obj = Molecule(composition)
              obj.chemicalComposition = composition;
          end
  
      ...
  
      end
  
      ...
  
  end
  </code></pre>
  
  <p>When I try to get an instance from MoleculeType, I get <strong>"Cannot call the constructor of 'media.MoleculeType' outside of its enumeration block."</strong> error.
  I couldn't figure out where it tries to call MoleculeType constructor so I get this error, because there is no reference to MoleculeType constructor in my code.</p>
  
  <p>Please help me out. Thanks in advance.</p>
  
  <p>Hint: I created enum classes without error before and they were having primitive values inside (e.g. <code>O2(32)</code>). Problem arise when I try to use object types inside enumerations (like in this question: <code>O2(media.ElementalComposition)</code>). I searched this in MATLAB documentation, there is no example. Documentation neither provide an example nor say that it is not supported.</p>