草庐IT

expected-exception

全部标签

c++ - 与 std::current_exception 关联的数据的生命周期

考虑以下代码:std::exception_ptreptr{std::current_exception()};constchar*msg=0;try{if(eptr!=std::exception_ptr{}){std::rethrow_exception(eptr);}}catch(conststd::exception&ex){msg=ex.what();}我可以在catch之外使用msg吗?换句话说,ex是否引用与eptr相同的异常实例?谢谢! 最佳答案 rethrow_exception的描述说:Throws:theexc

c++ - 分配器 : how are the standard containers expected to work internally?

作为这个问题的示例,我将使用std::vector。它的定义来自documentation如下:template>class vector;正如预期的那样,如果T是它的类型,分配器应该偏向于T。总之,下面的代码编译没有错误(至少,使用GCC)并运行:#include#include#includestructS{inti;doubled;std::strings;};intmain(){std::allocatoralloc;std::vector>v{alloc};v.push_back(S{});}在这里,我通过使用专注于int的分配器创建vector的S。它是合法的代码吗?我应该

c++ - 错误 - C++ 中的 "throws different exceptions"

我收到一个错误提示error:declarationof'virtualFXHost::~FXHost()'throwsdifferentexceptionserror:thanpreviousdeclaration'virtualFXHost::~FXHost()throw()'我不确定如何开始解决这个问题,我以前从未遇到过。在我的.h中我有:public:virtual~FXHost()throw();在我的.cpp中我有:FXHost::~FXHost(){gHost=NULL;}感谢指点。 最佳答案 函数声明末尾的throw

c++ - 为什么我得到 "error C2006: ' #include' : expected a filename, found 'identifier' "?

我在VisualC++Express2008中的源代码如下:#include“stdafx.h”#includeint_tmain(intargc,_TCHAR*argv[]){std::cout我正在使用IvorHorton的书VisualC++2008。这些是我遇到的错误。如何消除这些错误?1>e:\mydocuments\visualstudio2008\projects\hello\hello\hello.cpp(1):errorC2006:'#include':expectedafilename,found'identifier'1>e:\mydocuments\visual

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++ - 在 C 枚举错误中使用单词 "SING"到 "expected an identifier"

在头文件中我有以下枚举:namespaceOBJ_VERBS{enum{zero,CUDDLE,EMBRACE,FLIP,GROPE,HUG,KISS,LICK,NUDGE,PAT,PINCH,POKE,PULL,RUB,SHAKE,SQUEEZE,TAP,TUG,TURN,WAVE,PEER,PET,CLENCH,CURSE,NUZZLE,SNAP,STROKE,TWIRL,LEAN,GRIP,SMELL,GRUNT,SQUEAL,SCOLD,GAZE,WIND,SPIT,SPIN,DANCE,SING,zTOTAL};constint_MAX_=int(OBJ_VERBS::zTO

c++ - C++ : "expected primary-expression before ‘>’ token"中的两个模板

这个问题在这里已经有了答案:WhereandwhydoIhavetoputthe"template"and"typename"keywords?(8个答案)关闭7年前。最小工作示例:#includestructPrinter{templatestaticvoidprint(Telem){std::coutstructMain{templatevoidprint(Telem){//Inthiscase,thecompilercouldguessTfromthecontext//Butinmycase,assumethatIneedtospecifyT.printer_t::print(e

c++ - C++ 代码错误 "expected constructor, destructor, or type conversion before ‘(’ token ”和 "no matching function for call to ..."

真正尝试解决错误,仔细检查所有内容。请帮忙。c++新手,请多关照。头文件(.h)#ifndefGUARD_Optimized_quick_sort_h#defineGUARD_Optimized_quick_sort_h#include#include#includeusingnamespacestd;templateclassoptimized_quick_sort{public:optimized_quick_sort(vectorarray){this->array=array;}optimized_quick_sort(listarray){vectortemp(array.b

c++ - 函数异常规范和标准异常 - foo() throw(Exception)

在C++中,您可以像这样声明具有异常规范的函数:intfoo()constthrow(Exception);我找到了这两个链接:http://www.cplusplus.com/doc/tutorial/exceptions/和http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8l.doc%2Flanguage%2Fref%2Fcplr156.htm但有几件事最终没有答案......问题1:为什么要添加异常规范?它会带来任何性能提升吗?编译器会有什么不同?因为

c++ - "Expected class-name"...析构函数实现中的问题

我正在尝试实现堆栈和队列。我还获得了用于测试堆栈和队列的代码(以查看它们各自的功能是否正常工作)。我已经实现了stack和quete的功能,但是在尝试编译它们时出现错误:在析构函数“Stack::~Stack()”中'('标记前的预期类名在他们两个。以下是通用的Stack类:templateclassStack{Listlist;public:Stack();Stack(constStack&otherStack);~Stack();}列表类:templateclassList{ListItem*head;public:List();List(constList&otherList);