title: How do I pass one C++ class (reference) to another when using Cython?
body: <p>I'm trying to wrap a C++ module using Cython such that I can use it in Python.</p>
  
  <p>The module has multiple classes some of these have methods that have object references to another class as arguments.</p>
  
  <p>So lets say I have c++ classes called "foo" and "bar"- and cython wrap them thus:</p>
  
  <pre><code>cdef extern from "foobar.hpp" namespace "foobar":
      cdef cppclass foo:
          pass
      cdef cppclass bar:
          void kungFoo(foo &amp;f)
  </code></pre>
  
  <p>Now I want to make a wrapper class so that I can use it in Python...</p>
  
  <pre><code>cdef class pyFoo:
      cdef foo *thisptr
      def __cinit__(self):
          self.thisptr = new foo()
  
  cdef class pyBar:
      cdef bar *thisptr
      def __cinit__(self):
          self.thisptr = new bar()
      def kungFoo(self, f):
          self.thisptr.kungFoo(f.thisptr)
  </code></pre>
  
  <p>Well this results in "Error compiling Cython file." and "Cannot convert Python object to 'foo'".</p>
  
  <p>I think that this is because the cdef cppclass foo makes foo a "Python object" associated with the c++ class. However, this clever transformation doesn't seem to go back the other way when I need to pass it as an argument to another c++ class.</p>
  
  <p>This seems like a basic issue with cython to me - but I can't seem to find any solution after a couple of hours on google.</p>
  
  <p>Any help most welcome.</p>
  
  <p>Thanks!</p>