title: How to wrap a c++ class to python so that I can access its members' public methods (the member is an object pointer) using pybind11
body: <p>I have a c++ class, call it <em>Example</em>, which I want to wrap to Python using pybind11. <em>Example</em> contains a member which is a <em>MemberClassInterface</em> pointer, call it <em>memberClass</em>. <em>memberClass</em> is assigned an instance of <em>MemberClass</em>, which is derived from <em>MemberClassInterface</em>. In the python wrapper, I want to be able to access the <em>memberClass</em> object's public methods, but dont know how to do so. Below is the structure which I tried to explain here in text.</p>
  
  <pre><code>class MemberClass : public MemberClassInterface{
    public:
      MemberClass();
      ~MemberClass();
      someFunc(); //virtual func in interface.
  }
  someFunc(){
  //implementation..
  }
  </code></pre>
  
  <pre><code>class Example{
    public:
      Example();
      MemberClassInterface * memberClass;
  }
  Example(){
    this-&gt;memberClass = new MemberClass();
  }
  </code></pre>
  
  <p>Some wrapping like this is what I want to wrap; this is obv non-functioning, but I havent found how to do it. I also don't possess the best knowledge in c++ (or in python for that matter), so haven't been able to figure it out on my own either.</p>
  
  <pre><code>PYBIND_MODULE(pyexample,m){
    py::class_&lt;Example&gt;(m,"Example")
      .def(py::init&lt;&gt;())
      .def("memberClass", &amp;Example::memberClass); &lt;--- either something like this, or something like the
                                                       row below. 
      .def("someFunc", &amp;Example::memberClass-&gt;someFunc); &lt;-- how to achieve something similar to this?
                                                         It complains about someFunc not being non-static,
                                                         which I can understand...
  
  }
  </code></pre>
  
  <p>I would like to do be able of doing this:</p>
  
  <pre><code>&gt;&gt;&gt; import pyexample
  &gt;&gt;&gt; a = pyexample.Example()
  &gt;&gt;&gt; a.memberClass.someFunc() &lt;--- this is what I want to achieve.
  &gt;&gt;&gt; a.someFunc() &lt;---- or possibly this. But this seems to require someFunc to be static.. 
                   or embedding memberClass.someFunc() into another function calling
                   memberClass.someFunc...
  </code></pre>
  
  <p>I do not have any prior experience in wrapping and feel therefore rather lost here.
  I dont expext a perfect answer, but if someone have any idea or could guide me towards someone or something talking about this sort of wrapping, I would greatly appreciate it.</p>
  
  <hr>
  
  <p><strong>Update:</strong>
  pschill's answer solved it for me!</p>