Qsharedpointer类
我正在尝试按以下方式使用智能指针类,
class A
{
friend class B;
virtual methods ();
protected:
virtual ~classA();
}
class B:public QSharedPointer<class A>
{
class B();
~ class B();
}
我计划用 B 类替换出现的 A* 类。这种方法正确吗?
I am trying to use a smart pointer class in the following way
class A
{
friend class B;
virtual methods ();
protected:
virtual ~classA();
}
class B:public QSharedPointer<class A>
{
class B();
~ class B();
}
I plan to replace occurrences of Class A* with class B. Is this approach correct?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,这并不是真正的方法。看起来你这里的设计目标是让某人不可能在不将其放入智能指针的情况下分配 A 类型的对象。执行此操作的正常方法不是从智能指针继承,而是使您的类型具有
这里是使用 boost::shared_ptr 的示例(我现在没有安装 QT,但您应该能够用 QSharedPointer 替换 boost::shared_ptr 的所有实例)
No this is not really the way to do this. It looks like your design goal here is to make it impossible for someone to allocate an object of type A without putting it in a smart pointer. The normal way to do this is not to inherit from the smart pointer, but to make your type have
Here is an example using boost::shared_ptr (I do not have a QT installation right now, but you should be able to just replace all instances of boost::shared_ptr with QSharedPointer)