小编stu*_*023的帖子

使用这种智能指针铸造是否安全?

使用这种智能指针铸造是否安全?

APtr a(new A());
BPtr & b = (Bptr&)a; // this is it
Run Code Online (Sandbox Code Playgroud)

那里,

class A
{
public:
   virtual ~A(){}
   virtual void methodA() = 0;
}
typedef std::tr1::shared_ptr<A> APtr;

class B : public A
{
public:
   virtual ~B(){}
   virtual void methodB() = 0;
}
typedef std::tr1::shared_ptr<B> BPtr;

/////////////////////////////////////////////////////////////////////////////////

BPtr & b = a; //this way doesn't work
Run Code Online (Sandbox Code Playgroud)

c++ casting smart-pointers tr1

2
推荐指数
1
解决办法
1102
查看次数

标签 统计

c++ ×1

casting ×1

smart-pointers ×1

tr1 ×1