title: how do I return objects from a C++ function with ctypes?
body: <p>I have two C++ classes, Container and Item, that look like:</p>
  
  <pre><code>class Item{
  public:
      Item(std::string* name,int id);
      std::string* getName();
  private:
      std::string* name;
      int id;
  };
  
  class Container {
  public:
      Container();
      Item* getItem(int id);
  private:
      std::vector&lt;Item*&gt; items;
  };
  </code></pre>
  
  <p>I want to create and use Container in Python, so I wrote a C interface to compile a shared library:</p>
  
  <pre><code>extern "C" {
      Container* Container_init(){return new Container();}
      Item* Container_getItem(Container* container,int id){return container-&gt;getItem(id);}
      std::string* Item_getName(Item* item){return item-&gt;getName();}
  }
  </code></pre>
  
  <p>and a Python wrapper:</p>
  
  <pre><code>from ctypes import *
  
  lib = cdll.LoadLibrary(myLibPath)
  
  class Item(object):
      def getName(self):
          return lib.Item_getName(self.obj)
  
  class Container(object):
      def __init__(self):
          self.obj = lib.Container_init()
  
      def getItem(self,id):
          return lib.Container_getItem(self.obj,id)
  
  
  lib.Container_getItem.restype = Item
  lib.Container_getItem.argtypes = [c_void_p,c_int]
  
  c = Container()
  print c.getItem(5).getName()
  </code></pre>
  
  <p>When this code runs, it raises a TypeError "object() takes no parameters" at line</p>
  
  <pre><code>return lib.Container_getItem(self.obj,id)
  </code></pre>
  
  <p>I read about restype and argtype in the <a href="http://docs.python.org/2/library/ctypes.html#return-types" rel="nofollow">documentation</a> but I'm obviously missing something, how can I make <code>Container.getItem</code> return an Item in Python?</p>