概念std :: derived_from当参数是一个明智的指针时
我有类似的功能
bool RegisterModel (std::shared_ptr<DerivedA> model) { }
bool RegisterModel (std::shared_ptr<DerivedB> model) { }
,我想利用C ++ 20概念并这样实现:
bool RegisterModel (std::derived_from<BaseClass> auto model) { }
这是不起作用的,因为我传递了共享的指针。有可能需要一个共享指针,该指针容纳baseclass
的对象?
I have a few functions like so
bool RegisterModel (std::shared_ptr<DerivedA> model) { }
bool RegisterModel (std::shared_ptr<DerivedB> model) { }
and i would like to make use of c++ 20 concepts and implement it like this:
bool RegisterModel (std::derived_from<BaseClass> auto model) { }
This does not work, because i'm passing in shared pointers. It is somehow possible to require a shared pointer that holds an object derived from BaseClass
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从
std :: shared_ptr&lt; t&gt;
中推导t
>Deduce the
T
from astd::shared_ptr<T>
and constrain that: