title: Referencing a C++ allocated object in pybind11
body: <p>I'm trying to create a python binding with pybind11 that references a C++ instance whose memory is handled on the C++ side. Here is some example code:</p>
  
  <pre><code>import &lt;pybind11/pybind11&gt;
  
  struct Dog {
      void bark() { printf("Bark!\n"); }
  };
  
  int main()
  {
    auto dog = new Dog;
    Py_Initialize();
    initexample(); // Initialize the example python module for import 
  
    // TBD - Add binding  between dog and example.dog .
  
    PyRun_StringFlags("import example\n"
                      "\n"
                      "example.dog.bark()\n"  // Access the C++ allocated object dog.
                      , Py_file_input, main_dict, main_dict, NULL);
    Py_Finalize();
  }
  </code></pre>
  
  <p>I'm stuck on how to create the link between the python <code>example.dog</code> and the C++ <code>dog</code> variable. </p>
  
  <p>I can't use <code>py:class_&lt;Dog&gt;.def(py::init&lt;&gt;())</code> as that will allocate a new instance of <code>Dog</code>, which is not what I want. </p>