title: Ctypes: Extended Struct/Pointer (Inheritance)
body: <p>I would like to send extended Struct/Pointer(In the example below <strong>PY_LayerExtended</strong>) from Python to C++ but I've got an error.</p>
  <p>My C++ code supposed to be like this:</p>
  <pre><code>typedef struct PY_LayerBase {
  } PY_LayerBase;
  
  
  typedef struct PY_LayerExtended : PY_LayerBase {
  } PY_LayerExtended;
  
  
  typedef struct PY_Layer {
      PY_LayerBase* layerBase;
  } PY_Layer;
  
  
  // My Method
  void parseTest(PY_Layer *py_layer) {
  
      // I cast PY_LayerBase to PY_LayerExtended
      PY_LayerExtended* py_layerExt = static_cast&lt;PY_LayerExtended*&gt;(py_layer-&gt;layerBase);
  
  }
  </code></pre>
  <p>And my Python code looks like this:</p>
  <pre><code>import ctypes
  from ctypes import *
  
  class PY_LayerBase (ctypes.Structure):
      _fields_ = []
  
  
  class PY_LayerExtended (PY_LayerBase):
      _fields_ = []
  
  
  class PY_Layer(ctypes.Structure):
      _fields_ = [(&quot;layerBase&quot;, PY_LayerBase)]
  
  
  my_lib = cdll.LoadLibrary('mylib.dll')
  
  py_layer_ext = PY_LayerExtended()
  py_layer = PY_Layer(pointer(py_layer_ext))
  
  parseTest = my_lib.parseTest
  parseTest.argtypes = (POINTER(PY_Layer))
  
  # Run C++
  my_ptr = parseTest(pointer(py_layer))
  </code></pre>
  <p>And when I run Python I've got an error:</p>
  <p><strong>TypeError: incompatible types, PY_LayerExtended instance instead of PY_LayerBase instance</strong></p>
  <p>The error happens on the line: <strong>py_layer = PY_Layer(pointer(py_layer_ext))</strong></p>