草庐IT

weak_intrusive_pointer

全部标签

c++ - Visual Studio 2015 “non-standard syntax; use ' &' to create a pointer to member”

我正在学习C++并尝试制作一个小游戏井字游戏。但我不断得到C3867,非标准语法;使用'&'创建一个要记住的指针。这是我的井字游戏.h:#pragmaonce#includeusingnamespacestd;classTicTacToe{public:TicTacToe();stringgetName1();stringgetName2();voidprintBoard();voidclearBoard();voidsetName1(stringplayer1Name);voidsetName2(stringplayer2Name);voidsetSign1(stringplayer

c++ - 关于weak_ptr的线程安全

std::shared_ptrg_s=std::make_shared(1);voidf1(){std::shared_ptrl_s1=g_s;//readg_s}voidf2(){std::shared_ptrl_s2=std::make_shared(3);std::threadth(f1);th.detach();g_s=l_s2;//writeg_s}关于上面的代码,我知道读取和写入相同shared_ptr的不同线程会导致竞争条件。但是weak_ptr呢?下面的代码中是否有任何竞争条件?(我的平台是微软VS2013。)std::weak_ptrg_w;voidf3(){std:

c++ - 关于weak_ptr的线程安全

std::shared_ptrg_s=std::make_shared(1);voidf1(){std::shared_ptrl_s1=g_s;//readg_s}voidf2(){std::shared_ptrl_s2=std::make_shared(3);std::threadth(f1);th.detach();g_s=l_s2;//writeg_s}关于上面的代码,我知道读取和写入相同shared_ptr的不同线程会导致竞争条件。但是weak_ptr呢?下面的代码中是否有任何竞争条件?(我的平台是微软VS2013。)std::weak_ptrg_w;voidf3(){std:

c++ - `weak_ptr::expired` 对象 dtor 中的行为

考虑以下代码:#include#includeusingnamespacestd;classT;std::weak_ptrwptr;classT{public:T(){}~T(){std::cout();wptr=ptr;std::cout在这段代码中,我试图找出weak_ptr是否在对象销毁阶段过期。似乎是这样。输出是:notexpiredindtorexpired我使用gcc-5.1和ideone.现在,我有另一个问题。我找不到任何说明这是标准行为的文档。是否保证以这种方式工作,总是? 最佳答案 Now,Ihaveanother

c++ - `weak_ptr::expired` 对象 dtor 中的行为

考虑以下代码:#include#includeusingnamespacestd;classT;std::weak_ptrwptr;classT{public:T(){}~T(){std::cout();wptr=ptr;std::cout在这段代码中,我试图找出weak_ptr是否在对象销毁阶段过期。似乎是这样。输出是:notexpiredindtorexpired我使用gcc-5.1和ideone.现在,我有另一个问题。我找不到任何说明这是标准行为的文档。是否保证以这种方式工作,总是? 最佳答案 Now,Ihaveanother

c++ - 错误 : called object type 'int' is not a function or function pointer

我在这里写了一个快速排序:voidswap(int&a,int&b);intmid(intlo,inthi);//Myquicksortimplementationvoidsort(intvec[],intlo,inthi){intmid;if(hi>lo){inti=lo+1;intj=hi;intp=mid(lo,hi);swap(vec[lo],vec[p]);mid=vec[lo];while(i=mid);swap(vec[i],vec[j]);}}i++;swap(vec[lo],vec[i]);sort(vec,lo,i);sort(vec,j,hi);}}voidswa

c++ - 错误 : called object type 'int' is not a function or function pointer

我在这里写了一个快速排序:voidswap(int&a,int&b);intmid(intlo,inthi);//Myquicksortimplementationvoidsort(intvec[],intlo,inthi){intmid;if(hi>lo){inti=lo+1;intj=hi;intp=mid(lo,hi);swap(vec[lo],vec[p]);mid=vec[lo];while(i=mid);swap(vec[i],vec[j]);}}i++;swap(vec[lo],vec[i]);sort(vec,lo,i);sort(vec,j,hi);}}voidswa

c++ - 为什么我不能将 nullptr 转换为 weak_ptr<>

classMyClass{public:MyClass(std::weak_ptrparent){}}我想这样做:autonewInstance=std::make_shared(nullptr);或者weak_ptr参数的默认值为null,如:voidfunction(intarg,std::weak_ptrobj=nullptr);但是,我需要这样做:autonewInstance=std::make_shared(std::shared_ptr(nullptr));这是为什么呢? 最佳答案 因为weak_ptr在概念上只能从另

c++ - 为什么我不能将 nullptr 转换为 weak_ptr<>

classMyClass{public:MyClass(std::weak_ptrparent){}}我想这样做:autonewInstance=std::make_shared(nullptr);或者weak_ptr参数的默认值为null,如:voidfunction(intarg,std::weak_ptrobj=nullptr);但是,我需要这样做:autonewInstance=std::make_shared(std::shared_ptr(nullptr));这是为什么呢? 最佳答案 因为weak_ptr在概念上只能从另

c++ - 使用空大括号初始化程序 : pointer or reference? 的重载分辨率

这个问题在这里已经有了答案:Overloadresolution:assignmentofemptybraces(2个回答)关闭5年前。当我发现下面的代码输出“指针”时,我遇到了一个真实的WTF时刻。#include#includetemplatestructbla{staticvoidf(constT*){std::cout>::f({});}更改std::pairint的模板参数或任何其他原始类型,给出(至少对我而言)预期的“模棱两可的重载”错误。似乎内置类型在这里很特殊,因为任何用户定义的类型(聚合、非平凡、具有默认构造函数等)都会导致调用指针重载。我相信模板不是复制它的必要条件