与升压的static_cast :: shared_ptr的? [英] static_cast with boost::shared_ptr?

查看:142
本文介绍了与升压的static_cast :: shared_ptr的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是相当于一个的static_cast 的boost :: shared_ptr的

在换句话说,怎么做我不得不重写以下

 基础* B =新派生的();
派生* D =的static_cast<衍生*>(二);

当使用

的shared_ptr

 的boost :: shared_ptr的<基地以及GT; B(新派生的());
提高:: shared_ptr的<衍生GT; D =?


解决方案

使用的boost :: static_pointer_cast

 的boost :: shared_ptr的<基地以及GT; B(新派生的());
提高:: shared_ptr的<衍生GT; D =的boost :: static_pointer_cast<衍生GT;(二);

What is the equivalent of a static_cast with boost::shared_ptr?

In other words, how do I have to rewrite the following

Base* b = new Derived();
Derived* d = static_cast<Derived*>(b);

when using shared_ptr?

boost::shared_ptr<Base> b(new Derived());
boost::shared_ptr<Derived> d = ???

解决方案

Use boost::static_pointer_cast:

boost::shared_ptr<Base> b(new Derived());
boost::shared_ptr<Derived> d = boost::static_pointer_cast<Derived>(b);

这篇关于与升压的static_cast :: shared_ptr的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆