title: How to wrap a referenced c++ class in Cython?
body: <p>I'm having Problems to wrap one of the methods of the following mctdhBasis class: </p>
  
  <p><strong>mctdhBasis.h</strong>:</p>
  
  <pre><code>class mctdhBasis
  {
  public:
      //  mctdhBasis();
      mctdhBasis();
      ~mctdhBasis();
  
  void Initialize(string filename, ControlParameters&amp; config);
  .
  .
  .
  //mctdhNode is a custom class, which is defined in mctdhNode.h
  const mctdhNode&amp; MCTDHNode(size_t i)const;
  .
  .
  .
  };
  </code></pre>
  
  <p>In order to Initializing this class I use:</p>
  
  <p><strong>ControlParameters.h:</strong></p>
  
  <pre><code>class ControlParameters
  {
  public:
      ControlParameters();
      ~ControlParameters();
  
      void Initialize(string configfile, ostream &amp; log);
      .
      .
      .
      };
  </code></pre>
  
  <p>The mctdhNode class is defined in </p>
  
  <p><strong>mctdhNode.h:</strong></p>
  
  <pre><code>class mctdhNode
  : public Node
  {
   public:
      mctdhNode();
      mctdhNode(ifstream&amp; file, mctdhNode* up, mctdhNodePosition position_);
      ~mctdhNode();
  
      void Initialize(ifstream &amp; file, mctdhNode * up_, mctdhNodePosition position_);
  
      void info(ostream&amp; os=cout)const;
  .
  .
  .
  }
  </code></pre>
  
  <p>my cython code looks like follows:</p>
  
  <p><strong>mctdh.pyx:</strong></p>
  
  <pre><code>from libcpp.string cimport string
  
  cdef extern from "&lt;iostream&gt;" namespace "std":
      cdef cppclass ostream:
          ostream&amp; write(const char*, int) except +
      ostream cout
  
  cdef extern from "../MCTDH/ControlParameters.h":
      cdef cppclass ControlParameters:
          ControlParameters() except +
          void Initialize(string, ostream&amp;)
  
  cdef extern from "../MCTDH/mctdhBasis.h":
      cdef cppclass mctdhBasis:
          mctdhBasis() except +
          void Initialize(string, ControlParameters&amp;)
          const mctdhNode&amp; MCTDHNode(size_t i)
  
  cdef extern from "../MCTDH/mctdhNode.h":
      cdef cppclass mctdhNode:
          mctdhNode() except +
          void info(ostream&amp; os=cout)
  
  cdef ControlParameters config
  cdef mctdhBasis basis
  cdef const mctdhNode &amp; node
  
  cdef ControlParameters PyControlParameters(string para):
      cdef ControlParameters config
      config.Initialize(para, cout)
      return config
  
  cdef void PymctdhNode(para, filename, size_t i):
        config.Initialize(para, cout)
        basis.Initialize(filename, config)
        node[0] = basis.MCTDHNode(i)
  </code></pre>
  
  <p>After compiling these files, I get following error:</p>
  
  <pre><code>Error compiling Cython file:
  ------------------------------------------------------------
  ...
          mctdhNode() except +
          void info(ostream&amp; os=cout)
  
  cdef ControlParameters config
  cdef mctdhBasis basis
  cdef const mctdhNode &amp; node
                      ^
  ------------------------------------------------------------
  
  
  mctdh.pyx:32:21: C++ references cannot be declared; use a pointer instead
  </code></pre>
  
  <p>When I change the erroneous line to <code>cdef const mctdhNode * node</code>, I get the following error:</p>
  
  <pre><code>Error compiling Cython file:
  ------------------------------------------------------------
  ...
      return config
  
  cdef void PymctdhNode(para, filename, size_t i):
        config.Initialize(para, cout)
        basis.Initialize(filename, config)
        node[0] = basis.MCTDHNode(i)
           ^
  ------------------------------------------------------------
  
  
  mctdh.pyx:42:10: Assignment to const dereference
  </code></pre>
  
  <p>Finally I changed 
  <code>node[0] = basis.MCTDHNode(i)</code> to <code>(&amp;node)[0] = basis.MCTDHNode(i)</code></p>
  
  <p>But still it doesn't work:</p>
  
  <pre><code>Error compiling Cython file:
  ------------------------------------------------------------
  ...
      return config
  
  cdef void PymctdhNode(para, filename, size_t i):
        config.Initialize(para, cout)
        basis.Initialize(filename, config)
        (&amp;node)[0] = basis.MCTDHNode(i)
                                   ^
  ------------------------------------------------------------
  
  
  mctdh.pyx:42:34: Cannot assign type 'const mctdhNode &amp;' to 'const mctdhNode *'
  </code></pre>
  
  <p>So basically my question is how too declare a variable with the type of 'const mctdhNode &amp;'.     </p>