草庐IT

weakly-referenced

全部标签

c++ - 异常 : bad_weak_ptr while shared_from_this

当我这样做时出现异常:std::bad_weak_ptr->shared_from_this()templateclasspainter_record_t{.......private:std::shared_ptr_owner;}这里我想在构造函数中设置“问题”对象:templateclassstream_record_t:publicpainter_record_t{public:stream_record_t(std::shared_ptrowner):painter_record_t(owner){//...}}我有基类:classi_painter_t{public:virt

c++ - 对象 std::shared_ptr 是否可以通过它的 std::weak_ptr 找到?

所以我有一个std::vector>myListOfT;我有一个std::weak_ptrptrToOneT;它是从用于填充该容器的指针之一创建的(假设我将它放在回调函数中)。威尔std::find在那个容器和我的weak_ptr给我一个原始shared_ptr的迭代器(如果集合中存在这样的一个)?它是在标准的某处得到保证还是依赖于此实现? 最佳答案 通过使用std::weak_ptr::owner_before,我们可以不锁定weak_ptr。我将使用比必要的稍微冗长的解决方案并引入owner_equal,它与std::owner

c++ - 错误 LNK2019 : unresolved external symbol "" referenced in function

我目前在编译代码时遇到以下错误:errorLNK2019:unresolvedexternalsymbol"public:void__thiscallAgent::printSelf(void)"(?printSelf@Agent@@QAEXXZ)referencedinfunction"public:void__thiscallWorld::processMouse(int,int,int,int)"(?processMouse@World@@QAEXHHHH@Z)World.obj这是我的代码代理.h:classAgent{public:Agent();voidprintSelf(

c++ - 构造一个 constexpr std::weak_ptr

根据std::weak_ptr文档可以构造一个constexprweak_ptr:#includeconstexprweak_ptrfoo{};但是,使用clang尝试此操作会产生编译错误,提示constexpr变量不能具有非文字类型'conststd::weak_ptr',这是因为weak_ptr有一个用户提供的析构函数。(确实如此,查看libc++header)我的问题是,这是一个libc++错误,还是做constexprweak_ptr只是没有意义并且拥有constexpr默认构造函数是一个错误?我可以期待它在未来发挥作用吗? 最佳答案

c++ - weak_ptr 和父子循环依赖

我目前有类似以下内容:classParent{//justasinglechild...forsakeofsimplicity//nootherclassholdsashared_ptrreferencetochildshared_ptr_child;System*getSystem(){...}}classChild{weak_ptr_parent;~Child{_parent.lock()->getSystem()->blah();}}Child析构函数总是崩溃,因为当~Child()运行时_parent总是过期。是否有针对这种怪现象的典型解决方案?简而言之,有没有办法在~Chil

C++ STL:将派生虚拟类用作 std::sort() 的 "Strict Weak Ordering"

我使用std::sort()撞墙了。我有一个纯虚类(名为Compare),方法的调用者派生自该类(名为MyComp)。我将纯虚拟类用于我的API原型(prototype):voidObject::DoSort(Compare&comp){std::sort(this->mKeys.begin(),this->mKeys.end(),comp);}来电者:classMyComp:publicCompare{booloperator()(constRow*r1,constRow*r2){...}}cmp;...obj->DoSort(cmp);Linux上的g++编译器提示:“无法分配类型

c++ - 错误 LNK2019 : unresolved external symbol referenced in function main

我正在尝试用C++运行我的简单汇编代码。我只有两个文件“.cpp”文件和“.asm”文件。编译时出现错误(见下文)。如果有人能提供帮助,我将不胜感激...:)这是我的“main.cpp”文件#includeusingnamespacestd;extern"C"intGetValueFromASM();intmain(intargc,char*argv[]){cout我还有一个简单的“asm.asm”文件.codeGetValueFromASMprocmovrax,3254retGetValueFromASMendpend尝试构建时出现此错误:1>main.obj:errorLNK201

c++ - weak_ptr 奇怪的复制构造函数

以下是weak_ptr的2个构造函数:http://msdn.microsoft.com/en-us/library/bb982126.aspxweak_ptr(constweak_ptr&);templateweak_ptr(constweak_ptr&);实际代码(来自内存):weak_ptr(constweak_ptr&_Other){//constructweak_ptrobjectforresourcepointedtoby_Otherthis->_Resetw(_Other);}templateweak_ptr(constweak_ptr&_Other,typenameen

c++ - weak_ptr C++ 中的比较运算符

我在新的STL成员中还是个新手。谁能指出为什么这段代码会出现段错误?#include#include#include#include#includeusingnamespacestd;structStubClass{weak_ptrb;intc;friendbooloperator==(StubClassx,StubClassy);friendbooloperatorx):b(x){c=5;}};booloperator==(StubClassd,StubClassc){returnd.b==c.b;}booloperatorspPtr(newstring("Hello"));weak

c++ - map 中过期的 weak_ptr 会发生什么

我想了解weak_ptr已过期的映射中的条目(类型为boost::weak_ptr)会发生什么。map中的相应条目是否会自动删除?键是一个整数,对应的值是一个weak_ptr。我写的示例代码,但无法编译#include#include#includeusingnamespacestd;classFoo:publicboost::enable_shared_from_this{public:Foo(intn=0):bar(n){std::coutinc_ref(){returnshared_from_this();}private:intbar;};std::map>mappy;intm