草庐IT

copy_pointer

全部标签

c++ - 将 std::exception 转换为 EXCEPTION_POINTERS

我可能完全误解了如何使用GoogleBreakpadAPI,如果是这种情况,我愿意接受评论/建议/粗鲁的评论。我正在尝试调用以下C++函数:boolWriteMinidumpForException(EXCEPTION_POINTERS*exinfo);我有一个对std::exception的引用:try{returnQApplication::notify(receiver,event);}catch(std::exception&ex){eh_.WriteMinidumpForException(?????);//...dosomemorestuffandultimatelykil

c++ - 使用字符串数组 : arrays of pointers - Are they like multidimensional arrays?

我最近一直在阅读C++fordummies,要么书名用词不当,要么他们不指望我。在关于使用带有字符串的指针数组的部分中,他们展示了一个函数,我完全被难住了,不知道该转向哪里。char*int2month(intnMonth){//checktoseeifvalueisinrangif((nMonth12))return"invalid";//nMonthisvalid-returnthenameofthemonthchar*pszMonths[]={"invalid","January","February","March","April","May","June","July","A

c++ - 使用 std::copy 复制所有元素的地址

我正在尝试获取给定集合的所有元素的地址并将它们复制到std::set。基本上,而不是std::sets1;std::copy(first1,last1,std::inserter(s1,s1.begin()));我想插入他们的地址。像这样的东西:std::set>s1;std::copy(reference_iterator(first1),reference_iterator(last1),std::inserter(s1,s1.begin()));在这里,reference_iterator将是一个迭代器,返回其元素的地址,而不是元素,这与boostindirect_iterato

c++ - 在 copy-and-swap 习语中实现交换

正在关注Whatisthecopyandswapidiom和Howtoprovideaswapfunctionformyclass,我尝试像后者接受的答案选项2那样实现交换函数(具有调用成员函数的自由函数),而不是前一个链接中的直接友好自由函数。但是下面的不编译#include//Uncommentingthefollowingtwolineswon'tchangethestateofaffairs//classBar;//voidswap(Bar&,Bar&);classBar{public:Bar(unsignedintbottles=0):bottles(bottles){enf

c++ - 标准转换 : Array-to-pointer conversion

这是来自ISO的要点:标准转换:数组到指针的转换:$4.2.1Anlvalueorrvalueoftype“arrayofNT”or“arrayofunknownboundofT”canbeconvertedtoanrvalueoftype“pointertoT.”Theresultisapointertothefirstelementofthearray.谁能解释一下,如果可能的话,用一个示例程序。我已经看过这些链接,但我无法理解:ArrayandRvalueIthinkImayhavecomeupwithanexampleofrvalueofarraytype

c++ - 从结构中调用 Pointer-to-Member-Function 指向的函数

我有一个具有特殊数据结构的类Test。Test类的成员是std::map,其中键是std::string,映射值是struct定义如下:typedefstruct{void(Test::*f)(void)const;}pmf_t;map初始化正常。问题是当我试图调用指向的函数时。我编了一个重现问题的玩具示例。在这里:#include#includeusingnamespacestd;classTest;typedefvoid(Test::*F)(void)const;typedefstruct{Ff;}pmf_t;classTest{public:Test(){pmf_tpmf={&T

C++ 标准 : return by copy to initialize a reference without RVO: is there any copy?

让我们考虑下一个示例:structbig_type{};//Returnbycopyautofactory(){returnbig_type{};}voidany_scope_or_function(){big_type&&lifetime_extended=factory();}假设RVO被禁止或根本不以任何方式存在,big_type()是否会或可以被复制?还是将引用直接绑定(bind)到return语句中构造的临时对象?我想确保big_type析构函数仅在any_scope_or_function结束时被调用一次。我使用C++14,以防某些行为在标准版本之间发生变化。

C++ 问题 : pointers/memory addresses and subclasses

为什么允许我们运行这段代码:int*FunctionB(intx){inttemp=30;//morecodereturn&temp;}在我看来,我并没有像我说过的那样返回。为什么我把返回类型声明为指针就可以返回一个内存地址。指针不是指向内存地址的东西,实际上不是内存地址吗?classImage:publicBMP{public:voidinvertcolors();voidflipleft();voidadjustbrightness(intr,intg,intb);private:};在编译之前的代码时我得到这个错误:image.h:3:error:expectedclass-na

c++ - std::sort 在 std:vector of pointers 上失败

以下代码在对vector进行排序时崩溃。#include#include#includeusingnamespacestd;structFoo{intx;//inty;Foo():x(0){}};structCmp{booloperator()(Foo*p1,Foo*p2)const{if(p1->x!=p2->x)returnp1->xx;//if(p1->y!=p2->y)returnp1->yy;returntrue;}};intmain(){vectorv;for(inti=0;i为什么会这样? 最佳答案 boolopera

c++ - 为什么这里调用的是 Copy Constructor 而不是普通的 Constructor 和重载的赋值运算符?

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:IsthereadifferenceinC++betweencopyinitializationanddirectinitialization?CopyconstructorsandAssignmentOperators我有一个C类,我在其中重载了Normal、复制构造函数和赋值运算符以打印被调用内容的踪迹。我写了以下代码来测试什么时候被调用?Cc1;-->NormalConstuctor..//understoodFineCc2;c2=c1;-->Normalconstructor+assignmentop