{"action":"closed","issue":{"url":"https://api.github.com/repos/wjakob/pybind11/issues/39","labels_url":"https://api.github.com/repos/wjakob/pybind11/issues/39/labels{/name}","comments_url":"https://api.github.com/repos/wjakob/pybind11/issues/39/comments","events_url":"https://api.github.com/repos/wjakob/pybind11/issues/39/events","html_url":"https://github.com/wjakob/pybind11/issues/39","id":122290754,"number":39,"title":"Accessing underlying C++ object from generic python object","user":{"login":"jtravs","id":1625247,"avatar_url":"https://avatars.githubusercontent.com/u/1625247?v=3","gravatar_id":"","url":"https://api.github.com/users/jtravs","html_url":"https://github.com/jtravs","followers_url":"https://api.github.com/users/jtravs/followers","following_url":"https://api.github.com/users/jtravs/following{/other_user}","gists_url":"https://api.github.com/users/jtravs/gists{/gist_id}","starred_url":"https://api.github.com/users/jtravs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jtravs/subscriptions","organizations_url":"https://api.github.com/users/jtravs/orgs","repos_url":"https://api.github.com/users/jtravs/repos","events_url":"https://api.github.com/users/jtravs/events{/privacy}","received_events_url":"https://api.github.com/users/jtravs/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-12-15T15:01:02Z","updated_at":"2015-12-15T15:22:07Z","closed_at":"2015-12-15T15:22:07Z","body":"I expect this is a trivial question, and apologies for that, but I cannot work out how to do this.\r\n\r\nIf I have exposed a C++ type to python using pybind11 and created several instances of it in python, stored in a list, what is the best way to obtain these instances in a different C++ function (jn this case the constructor of another class). I tried passing the list directly to a function expecting  a ```std::vector<MyType>``` but this does not work. i.e.\r\n```C++\r\npy::class_<AnotherType>(m, \"AnotherType\")\r\n    .def(\"__init__\",\r\n             [](AnotherType &instance, std::vector<MyType> instances) {\r\n    ...\r\n    }\r\n```\r\nI also wrote a lambda function in C++ to accept a ```py::list``` object; that worked, but I do not know how to extract the C++ types from the py::objects inside the list.\r\n```C++\r\npy::class_<AnotherType>(m, \"AnotherType\")\r\n     .def(\"__init__\",\r\n             [](AnotherType &instance, py::list instances) {\r\n                 for (auto inst : instances) {\r\n                    //what do I do here?\r\n                 }\r\n    ...\r\n    }\r\n```\r\n\r\nWhat I actually want in the end is a ```std::vector<std::shared_ptr<MyType>>```.\r\n\r\nWhat is the best way to achieve this?"}}