struct Base
{
virtual Base* getObject()
{
return this;
}
};
struct Derived : Base
{
Derived* getObject() override
{
return this;
}
};
什么是智能指针等价于关键字
this
和整个协变返回类型结构?
编辑:
当我尝试返回
this
并使用 unique_ptr<Base>
作为返回值时,出现编译时错误,我无法将 Base*
转换为 unique_ptr<Base>
。