Python Pybind-使用指向派生类的共享指针调用函数

Python Pybind-使用指向派生类的共享指针调用函数,python,c++,python-3.x,c++17,pybind11,Python,C++,Python 3.x,C++17,Pybind11,我有以下设置(1个基类,1个派生类,1个容器)。容器将共享的\u ptr作为输入 #包括 名称空间py=pybind11; 结构基{}; 派生结构:公共基{}; 结构容器{void input(const std::sharedptr&ptr){}; PYBIND11_模块(PybindTest,m) { py::class_m(Base)).def(py::init()); py::class_m,“派生”).def(py::init()); py::类_m(容器) .def(py::init

我有以下设置(1个基类,1个派生类,1个容器)。容器将
共享的\u ptr
作为输入

#包括
名称空间py=pybind11;
结构基{};
派生结构:公共基{};
结构容器{void input(const std::sharedptr&ptr){};
PYBIND11_模块(PybindTest,m)
{
py::class_m(Base)).def(py::init());
py::class_m,“派生”).def(py::init());
py::类_m(容器)
.def(py::init())
.def(“输入”和容器::输入);
}
在C++中,我可以通过<代码> SyddYPPTR <代码>或<代码> SydDypTr>代码>到<代码>输入< /代码>函数。但在Python中,我得到一个错误:

将PybindTest导入为p
p、 容器().输入(p.Base())#一切正常
p、 Container().input(p.Derived())#抛出错误
#TypeError回溯(最近一次调用上次)
#在
#1将PybindTest作为p导入
#2 p.容器().输入(p.基())
#--->3 p.容器().输入(p.派生())
# 
#TypeError:input():函数参数不兼容。支持以下参数类型:
#     1. (self:PybindTest.Container,arg0:PybindTest.Base)->None
# 
#调用时使用:,
我试过玩类似的东西

.def(“输入”,py::重载_cast(&Container::输入))
.def(“输入”,[](const std::shared_ptr&ptr){this->input(ptr);})
但这两个都不能编译有什么建议吗?

我将Windows 10与Python 3.6 x64一起使用,并使用VS 2019编译所有内容。

正如@n.m.建议的那样:

py::class_m(派生的)
.def(py::init());

从(方法1:模板参数)

中,您可能希望通过
的一个额外参数通知Python Base是派生的基。我应该按照
的顺序在哪里添加它?