草庐IT

exception_type

全部标签

c++ - C/C++ 指针,ptr+1 = ptr +1 byte 还是 ptr+1*sizeof(pointer_type)?

有any_type*ptr=(any_type*)malloc(sizeof(any_type)*size);my_ptr=ptr+1;memcpy(dst,my_ptr,sizeof(any_type));my_ptr会指向ptr之后的1个字节,还是指向ptr之后的sizeof(any_type)字节?对齐选项如何影响答案?有符号/无符号类型是否不同? 最佳答案 指针运算是在指针的静态类型[*]的大小上进行的,所以它会有效地添加sizeof*ptr。成员的对齐方式将作为类型的对齐方式(对象末尾的填充)考虑到对象的大小。struct

解决:requests.exceptions.SSLError: HTTPSConnectionPool(host=‘x‘,port=x): Max retries exceeded with url

解决:requests.exceptions.SSLError:HTTPSConnectionPool(host=‘lv-pc-api-sinfonlineb.ulikecam.com’,port=443):Maxretriesexceededwithurl:/get(CausedbySSLError(SSLError(1,‘[SSL:WRONG_VERSION_NUMBER]wrongversionnumber(_ssl.c:1123)’)))文章目录解决:requests.exceptions.SSLError:HTTPSConnectionPool(host=‘lv-pc-api-sin

C++ STL type_traits 问题

我在看最新的C9lecture并注意到一些有趣的事情..在他对type_traits的介绍中,Stephan使用了以下(如他所说,人为的)示例:templatevoidfoo(Tt,true_type){std::coutvoidfoo(Tt,false_type){std::couttemplatevoidbar(Tt){foo(t,typenameis_integral::type());}这似乎比:复杂得多templatevoidfoo(Tt){if(std::is_integral::value)std::cout后一种做法有问题吗?他的方法更好吗?为什么?谢谢。

c++ - 如何摆脱 - 来自 NULL 的 "warning: converting to non-pointer type ' 字符”?

我有这段代码:intmyFunc(std::string&value){charbuffer[fileSize];....buffer[bytesRead]=NULL;value=buffer;return0;}行-buffer[bytes]=NULL给我一个警告:convertingtonon-pointertype'char'fromNULL。我如何摆脱这个警告? 最佳答案 不要使用NULL?它一般是为指针保留的,你没有指针,只有一个简单的char。只需使用\0(空终止符)或简单的0。

c++ - `void func() throw(type)` 有什么意义?

我知道这是一个有效的C++程序。函数声明中的throw有什么意义?据我所知,它什么都不做,也不用于任何事情。#includevoidfunc()throw(std::exception){}intmain(){return0;} 最佳答案 它指定任何std::exception都可以从func()中抛出,除此之外别无他法。如果抛出其他东西,它将调用一个unexpected()函数,该函数默认调用terminate()。这意味着抛出其他东西几乎肯定会以与未捕获异常相同的方式终止程序,但实现必须强制执行此操作。这通常与在func()周围

c++ - 在 Google Test 中打印 exception.what()

我的一些代码抛出使用if(failure)throwstd::runtime_error("abadthinghappened:...");我正在使用GoogleTest和TeamCity自动执行我的测试。它在Windows上运行,所以我使用--gtest_catch_exceptions参数在发生意外异常时将测试报告为失败。但是,GoogleTest只是简单地使测试失败,并显示一条类似的消息Exceptionthrownwithcode0xe06d7363inthetestbody.in(null)line-1这不是很有帮助。我宁愿有这样的消息Exceptionthrown:"aba

c++ - 跨线程复制 boost::exception 崩溃

下面的示例代码将boost::exception对象从1个线程复制/传输到另一个线程,由于异常/exception_ptr内部状态销毁期间的竞争条件而崩溃。我不确定解决它的最佳方法是什么。使用的boost版本是1.42,平台是在双核Intelm/c上运行的Ubuntulucid。编译器是gcc4.4.3。#include#include#includestructException:publicvirtualstd::exception,publicvirtualboost::exception{};structMyException:publicvirtualException{};

c++ - 无法在 VS 14 CTP : conditional expression of type 'void' is illegal 中使用 auto 声明 lambda

使用VisualStudio2014CTP、C++(v140)编译器:autogp=[&](BYTE*buff){autogp1=[](char*bff,char**p1){*p1=strstr((char*)bff,"(");return(*p1);};};错误:conditionalexpressionoftype'void'isillegal(也许auto真的输入错误?)如果我将内部lambda声明为std::functiongp1然后就可以了是我做错了什么还是编译器错误? 最佳答案 我没有运行2014,但您可能需要指定内部l

c++ - 使用前向声明时如何修复 "field has incomplete type"错误

如注释中所述,此代码抛出编译器错误error:field‘fTarget’hasincompletetype。为什么会这样?我只是分配那个字段而不做任何需要知道里面是什么的操作......或者我是?也许它无法弄清楚复制构造函数?classFSRVertex;//fwdclassFSREdge{public:charfC;FSRVertexfTarget;//compilererrorFSREdge(charc,FSRVertextarget):fC(c),fTarget(target){}//compilererror};classFSRVertex{public:boost::uno

c++ - 错误 C2893 : Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...) noexcept(<expr>)'

下面是一个给出编译时错误的程序。这主要与D类中的Boo函数有关。我最终尝试使用多个线程来调用solve方法,但目前这对我来说似乎不太有效,无法做到这一点。错误是:1>d:\dummy\project1\trash.cpp(37):warningC4101:'d':unreferencedlocalvariable1>c:\programfiles(x86)\microsoftvisualstudio\2017\community1\vc\tools\msvc\14.11.25503\include\thr\xthread(240):errorC2672:'std::invoke':no