草庐IT

gray8_ptr_t

全部标签

c++ - 应该使用哪个 header 来使用 scoped_ptr

我想在我的C++应用程序中使用智能指针。使用stdscoped_ptr应该包含哪个头文件? 最佳答案 标准C++库中没有scoped_ptr。全部C++11smartpointers在标题中.如果你想要boost::scoped_ptr那么你需要boost/scoped_ptr.hpp. 关于c++-应该使用哪个header来使用scoped_ptr,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/q

c++ - 使用 shared_ptr 时奇怪的双析构函数调用

最后我找到了一个非常奇怪的错误,这是由两次调用析构函数引起的。这是重现错误的最少代码:#include#include#includeclasscEventSystem{public:cEventSystem(){std::cout(eventSystem);}voidonEvent(){}std::shared_ptrtileBrowser;};intmain(){cEventSystemeventSystem;cGuigui(eventSystem);}输出是:constructor:0x7fffffffe67fdestructor:0x7fffffffe2dfdestructor

c++ - 在赋值运算符中分配 std::shared_ptr

我正在创建自己的自定义Filter类以用于boost::filtered_graph。WeightMap概念必须具有默认构造函数、复制构造函数和赋值运算符。我创建了下面的类,它有一个std::shared_ptr私有(private)成员。我的问题是我应该如何编写赋值运算符。复制构造函数没有问题,但赋值运算符不起作用。classBFDMFilter{private:constBGraph*m_battlemap;conststd::shared_ptrm_mv_ab;public:BFDMFilter():m_battlemap(nullptr),m_mv_ab(){}BFDMFilt

c++ - std::unique_ptr 试图引用已删除的函数

我已经使用Unity一段时间了,然后回来使用VisualStudio2015做一些C++。我遇到了这个类定义classA{public:A();virtual~A();A(constA&)=delete;A&operator=(constA&)=delete;private:…}这个类是动态分配的,如下所示:ObjPtrobj=ObjPtr(newA());哪里ObjPtr是定义的类型,看起来像:typedefstd::unique_ptrobjPtr;并将这些创建的对象添加到std::vector使用std::move.有一次,我需要遍历对象列表,如果我找到满足我条件的对象,请保留一

c++ - 奇怪的运算符重载, "operator T& () const noexcept { return *_ptr; }"

我研究了一下,operator函数的格式是(returnvalue)operator[space]op(arguments){implementation}但是,在std::reference_wrapper实现中,有一个运算符重载函数声明为operatorT&()constnoexcept{return*_ptr;。这个运算符和T&operator()constnoexcept{return*_ptr;不同吗?}?.如果两者不同,那么第一个有什么用? 最佳答案 运算符T&()constnoexcept;是一个user-define

c++ - 为什么我不能将 std::unique_ptr 用作 "template<class> class"参数?

这段代码:#includetemplateclassPtr>classA{Ptrints;};usingB=A;产生以下错误(使用GCC6.3):a.cpp:6:28:error:type/valuemismatchatargument1intemplateparameterlistfor‘templateclassPtr>classA’usingB=A;^a.cpp:6:28:note:expectedatemplateoftype‘templateclassPtr’,got‘templateclassstd::unique_ptr’现在,我可以像这样解决这个问题:templateu

c++ - 如何获得指向 shared_ptr 的指针?

我现在正在破解一个旧的C代码,试着让它更像C++/Boost风格:有一个资源分配函数如下所示:my_src_type*src;my_src_create(&src,ctx,topic,handle_src_event,NULL,NULL);我尝试用shared_ptr包装src:shared_ptrpSrc;刚才忘记说了。我需要循环执行此操作std::map>dict;my_src_type*raw_ptr;BOOST_FOREACH(std::stringtopic,all_topics){my_src_create(&raw_ptr,ctx,topic,handle_src_eve

c++ - 代码审查问题——我应该允许将 auto_ptr 作为参数传递吗?

考虑我最近在我们的代码库中看到的以下示例代码:voidClassA::ExportAnimation(auto_ptranimation){...doessomething}//callingmethod:voidclassB::someMethod(){auto_ptranimation(newCAnimation(1,2));ClassAclassAInstance;classAInstance.ExportAnimation(animation)...dosomemorestuff}我不喜欢这样——我宁愿这样写:voidClassA::ExportAnimation(CAnima

c++ - 无法将参数 1 从 'cli::interior_ptr<Type>' 转换为 'CvCapture **'

我正在抓取一个视频帧如下CvCapture*capture=cvCreateFileCapture("PATH");我可以阅读视频并处理它。一切正常。但是当我尝试释放捕获时cvReleaseCapture(&capture);我明白了errorC2664:'cvReleaseCapture':cannotconvertparameter1from'cli::interior_ptr'to'CvCapture**'with[Type=CvCapture*]Cannotconvertamanagedtypetoanunmanagedtype函数在一个类中。publicrefclassLoc

c++ - 使用 std::shared_ptr 对象实例创建 boost::thread

我有以下两个代码段。第一个block按预期编译和工作。但是第二个block不编译。我的问题是,给定下面的代码,当尝试基于由shared_ptr代理的对象实例创建线程时,正确的语法是什么?#include#include#include#includestructfoo{voidboo(){}};intmain(){//Thisworks{foo*fptr=newfoo;boost::threadt(&foo::boo,fptr);t.join();deletefptr;}//Thisdoesn'twork{std::shared_ptrfptr(newfoo);boost::threa