腾讯云
开发者社区
文档
建议反馈
控制台
登录/注册
首页
学习
活动
专区
圈层
工具
MCP广场
文章/答案/技术大牛
搜索
搜索
关闭
发布
文章
问答
(9999+)
视频
沙龙
1
回答
从
第三方
定义
的
类
继承
时
的
shared_from_this
在尝试研究我
的
问题
时
,我已经阅读了许多关于堆栈溢出
的
帖子,内容涉及
shared_from_this
、bad_weak_ptr异常和多重
继承
。它们都建议您
从
enable_shared_from_this
继承
一个基
类
,然后
从
该基
类
派生。那么,当您必须
从
其派生
的
类
来自无法编辑
的
第三方
库
时
,该怎么办呢?<<
浏览 12
提问于2020-06-01
得票数 1
回答已采纳
2
回答
如何在超
类
和子类中使用std::enable_shared_from_this?
、
、
、
、
我有两个
类
A和B,其中B是A
的
子类。我需要这两个
类
都使用std::enable_shared_from_this。insertme(std::vector<std::shared_ptr<A>>& v) { v.push_back(
shared_from_this
>>& v) { std::cout << "B:
浏览 104
提问于2020-03-18
得票数 2
回答已采纳
2
回答
boost::
shared_from_this
的
Qt等价物?
、
我有一些
从
boost::
shared_from_this
派生
的
类
-如何在Qt中执行等效
的
类
?(无需重新实现类似的
shared_from_this
;我更喜欢无
继承
的
解决方案)
浏览 0
提问于2012-10-16
得票数 4
回答已采纳
1
回答
在基
类
中调用
shared_from_this
()
时
的
bad_weak_ptr
、
、
、
我有一个SuperParent
类
,一个Parent
类
(
从
SuperParent派生),它们都包含一个到Child
类
的
shared_ptr (其中包含一个到SuperParent
的
weak_ptr )。不幸
的
是,当我试图设置Child
的
指针
时
,我得到了一个bad_weak_ptr异常。SuperParent> { void InformChild(shared_ptr<Child> gra
浏览 0
提问于2012-02-21
得票数 5
回答已采纳
2
回答
获取指向派生
类
的
弱指针
、
、
、
我有一堆作为共享指针存储
的
派生
类
,我想知道是否有任何方法
从
对象内部获取weak_ptr到对象?我试过使用
shared_from_this
()函数,但问题是,由于它是派生
类
,所以当我使基
类
从
enable_shared_from_this
继承
时
,当派生
类
调用
shared_from_this
()
时
,它得到基
类
的
shared_ptr而不是派生
类<
浏览 0
提问于2016-07-28
得票数 3
回答已采纳
1
回答
接口方法和返回到此
的
智能指针(enable_shared_from_this)
、
、
、
我有一个实现接口(Geometry)
的
类
(LinkList)。我
的
示例底部
的
代码显然是错误
的
,所以我正在考虑实现std::enable_shared_from_this。Geometry能否安全地
继承
std::enable_shared_from_this<LinkList>,我能否安全地将getLinkList()方法更改为
shared_from_this
()?如果我
的
Geometry
类
有它
继承
浏览 2
提问于2014-08-01
得票数 1
回答已采纳
2
回答
在构造函数中使用
shared_from_this
()
、
、
正如您所知道
的
,不可能在对象
的
构造函数中使用std::enable_shared_from_this和
shared_from_this
()对,因为包含该类
的
shared_pointer还不存在。: std::weak_ptr<T> _construct_self; std::shared_ptr<T>
shared_from_this
在构造函数调用之前,我基本上使用了pointer
浏览 0
提问于2016-11-19
得票数 2
2
回答
Qt QObject和boost::enable_shared_from_this
、
、
、
、
我正在使用boost::enable_shared_from_this模板在两个
类
之间创建一个混合器。因此,我在这个
类
中添加了一个新功能: public Connection,{ ... }; 我以前在普通
类
(不是QtObject,只是一个C++普通
类
)中使用过这种方法,而且一切都正常。但是现在我对一个QMainWindow做了同样
的
浏览 3
提问于2013-09-10
得票数 0
回答已采纳
2
回答
Clang-Tidy:调用复制构造函数以外
的
基本构造函数
、
、
我收到了来自Clang
的
以下信息:守则是:{ explicit Node(Node *parent = nullptr) : parent(parent) { parent->children.insert(
shared_from_this
private: Node *parent; // C++14 "weak
浏览 13
提问于2022-08-14
得票数 0
1
回答
继承
类
中
的
shared_from_this
()类型错误(是否存在dyn.type感知
的
共享指针?)
、
、
、
、
我有一个使用enable_shared_from_this<>
的
基视图控制器
类
public std::enable_shared_from_this<ViewControllerclass GalleryViewController : public ViewController {} 当我试图将我当前
的
实例传递给
第三方
时
有一个(罕见
的
)条件,即
浏览 1
提问于2017-12-18
得票数 4
回答已采纳
2
回答
如何检查调用
shared_from_this
()是否有效?
、
我想使用
shared_from_this
()
从
通过引用传递
的
对象获取std::shared_ptr。但是,我希望对可能不在共享指针中、甚至可能没有动态分配
的
对象具有鲁棒性。是否有一种方法可以检查给定对象(
从
enable_shared_from_this
继承
并通过引用传递)在调用可能未
定义
的
调用
shared_from_this
()行为之前是否由共享指针进行管理
浏览 2
提问于2016-04-16
得票数 2
回答已采纳
1
回答
在Silverlight中合并程序集
、
我正在尝试使用
继承
自
第三方
控件
的
silverlight
类
库创建自
定义
控件(如telerik radcontrols),当我将
类
库dll添加到另一个项目中,并尝试使用自
定义
控件
时
,会出现一个错误,提示缺少
从
第三方
控件
继承
的
类
的
引用例如:如果我从一个radButton
继承
了我
的
客户控件,当我在其他项目中尝试我<em
浏览 1
提问于2010-07-30
得票数 2
2
回答
通过值传递共享指针和接受作为基
类
参数是如何工作
的
?
、
、
、
、
在这个程序中: : public chat_participant,在其中一个调用中,shared_ptrroom_.join(
shared_from_this
()); void join(chat_participant_ptr participant) 那么,上面的示例如何将particpant转换为指向
继承
的
类
实例
的
基
类
指针呢
浏览 2
提问于2013-05-28
得票数 1
回答已采纳
3
回答
检查是否存在C++成员函数,可能受到保护
、
、
、
、
我正在尝试检测一个
类
是否有特定
的
函数(特别是
shared_from_this
(),它是
从
std::enable_shared_from_this<Some Unknown Class>
继承
的
)。为了使事情变得更复杂,我需要知道它是否具有此功能,即使它是
从
远程基
类
继承
的
,还是使用受保护
的
访问
继承
的
。 我已经研究过其他问题,如,但是提供
的
浏览 6
提问于2014-03-01
得票数 36
1
回答
Boost echo服务器示例并在lambda中捕获此示例和
shared_from_this
()
、
、
、
在boost 示例中,有一个服务器
类
在新连接上创建会话: acceptor.async_accept(socket, [this](boost::system::error_code ec) {会话
类
继承
自std::enable_shared_from_this,因此在调用
shared_from_this
()
时
已经创建了一个控制块,并且不会发生未
定义
的
行为。在do_read函数中,
shared_from_this
()函数用于允许对内存中仍然存在
浏览 2
提问于2017-10-13
得票数 2
回答已采纳
2
回答
或者如何
从
从
unique_ptr
继承
的
类
返回enable_shared_from_this
、
、
、
、
我希望我
的
构建器方法Class::create()返回unique_ptr1)此设计没有强制执行共享所有权(和原子锁)。unique_ptr非常高效,具有与void*相同
的
大小。2)尽管如此,在
类
用户端移动到shared_ptr 还是很容易
的
(但只有当客户想要共享多个所有权
的
实例
时
)但。我需要一些
类
实例
的
方法来返回“这个”指针。如果我
从
enable_shared_from
浏览 2
提问于2017-12-01
得票数 4
回答已采纳
4
回答
如何同时对父对象和派生对象执行enable_shared_from_this
、
、
我有简单
的
基
类
和派生
类
,我希望它们都有
shared_from_this
()。这个简单
的
解决方案: void foo_do_it() cout<() return boost::static_pointer_cast<bar2>(foo::
shared_from_this
());pub
浏览 1
提问于2009-03-18
得票数 42
回答已采纳
1
回答
使用具有多重
继承
的
enable_shared_from_this
、
、
、
、
BI我在我
的
代码中使用了enable_shared_from_this,我不确定它
的
用法是否正确。class A: public std::enable_shared_from_this<A>public: {{ void foo2() auto ptr =
浏览 6
提问于2013-04-18
得票数 25
回答已采纳
2
回答
如何
从
作为同一模板实例
的
父
类
调用方法[boost::enable_shared_from_this]
、
();}; gcc抱怨
shared_from_this
模棱两可。*在这种情况下,在B
的
returnMe中使用boost::enable_shared_from_this<B>::
shared_from_this
()或this->boost::enable_shared_from_this<B>::
shared_from_this
()安全吗?*A和B都是
从
enable_shared_from_this
继承
的
,但参数不同。看起来是
浏览 0
提问于2015-04-02
得票数 0
2
回答
基
类
和派生
类
都从boost::enable_shared_from_this
继承
时
,错误
的
弱指针
、
、
、
、
我有一个派生自boost::enable_shared_from_this
的
基
类
,还有一个派生自该基
类
和boost::enable_shared_from_this
的
类
:public:}; int m
浏览 8
提问于2012-10-09
得票数 5
回答已采纳
点击加载更多
相关
资讯
Python 类的继承
类的继承—Python 基础
Python 类的继承与多态
List接口的实现类继承关系如何?
任务场景的学习:python定义类
热门
标签
更多标签
云服务器
ICP备案
实时音视频
对象存储
云直播
活动推荐
运营活动
广告
关闭
领券