草庐IT

non-void

全部标签

c++ - reinterpret_cast<int*>(char*) 与 static_cast<int*>(static_cast<void*>(char*)) - 使用哪个?

当你动态分配了一个char*类型的缓冲区并想将它转换为特定类型时,你是否应该使用类似的东西reinterpret_cast(char*)或者类似的东西static_cast(static_cast(char*))为什么?我个人很想使用后者,因为对我来说,它并不是真正的数据“重新解释”(而只是一种分配缓冲区的机械方式)而且它看起来不像是一个来源错误的方式可能与典型的reinterpret_cast相同,但这是正确的直觉吗? 最佳答案 AccordingtoDaveAbrahams,使用链式static_casts是强制指针类型的正确、

c++ - _wtoi 返回零 : input zero or non-numerical input?

_wtoi当不能转换输入,所以输入不是整数时,返回零。但同时输入可以为零。这是一种确定输入是否错误或为零的方法吗? 最佳答案 这是C++,您应该使用stringstream进行转换:#include#includeintmain(){usingnamespacestd;strings="1234";stringstreamss;ss>i;if(ss.fail()){throwsomeWeirdException;}coutboost的lexical_cast有一个更简洁、更简单的解决方案:#include//...std::stri

c++ - 如何解决 : undefined reference to `non-virtual thunk to ...`

我正在尝试弄清楚如何进一步解决此问题。我还想知道如何安装更新版本的ld(如果有意义的话)。所有涉及的包管理器都告诉我,我是最新的。代码在ubuntu12.04和12.10上使用g++(4.7.2)编译、链接和运行,但在FC17上编译失败并出现此错误。ArchiveServiceLib/debug-posix/libArchiveLib.a(NamedIflTiffCache.o):(.rodata._ZTV26UnlockingGenericFileHandle[_ZTV26UnlockingGenericFileHandle]+0x58):undefinedreferenceto`I

c++ - boost::shared_ptr 到 void * 反之亦然

我正在用C语言开发一个应用程序,我需要在其中使用第3方C++库。所以,我基本上是在C++库周围编写一个包装器,以便可以从我的纯C应用程序中调用它。库中的一些方法返回类型为boost::shared_ptr的指针,我需要将其转换为void*[forC]然后将其转换回boost::shared_ptr类型以重用它以进行进一步处理。我使用以下方式进行转换:作废*:void*func1(){//aftertheboost::shared_ptriscreatedreturnstatic_cast(SHARED_PTR.get())}来自void*:voidfunc2(void*VOID_PTR

c++ - 全局分配函数和 const void*

根据C++11,下面的代码是否构成“未定义行为”(由于使用了const_cast,请参见下面的引用)?constvoid*p=operatornew(123);operatordelete(const_cast(p));来自C++11标准(3.7.4.2.3)的相关引述:Thevalueofthefirstargumentsuppliedtoadeallocationfunctionmaybeanullpointervalue;ifso,andifthedeallocationfunctionisonesuppliedinthestandardlibrary,thecallhasnoeff

c++ - 警告 : non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]

这个问题在这里已经有了答案:C++ArrayInitializersWarnings(2个答案)关闭8年前。我刚刚在我的机器上安装了最新版本的cygwin和eclipseluna。它工作正常,我能够运行我的项目。但是,当我构建它们时,我收到了我不明白的警告。例如,这是我从“c++Primer”一书的网站上获得的头文件“Sales_item.h”的警告:warning:defaultedanddeletedfunctionsonlyavailablewith-std=c++11or-std=gnu++11[enabledbydefault]Sales_item()=default;^..

c++ - 理解返回 void 的 CAF actor 函数

我知道Actor可以通过功能来实现。以下代码片段来自CAFgithubexamples/hello_world.cpp.我知道第一个实现方法,它将几个消息处理程序绑定(bind)到actor。Actor将在后台处于事件状态并由事件触发,然后在调用self->quit时终止。但是第二个什么都不返回,它的消息处理程序在哪里?而且看起来没有任何类似self->quit的函数可以终止自身。hello_world返回时它还活着吗?或者它只是在then中完成响应后自行终止?behaviormirror(event_based_actor*self){return{[=](conststring&w

c++ - 了解 void f(const T& param) 中参数的类型

引用:EffectiveModernC++Item4.https://github.com/BartVandewoestyne/Effective-Modern-Cpp/blob/master/Item04_Know_how_to_view_deduced_types/runtime_output02.cppclassWidget{};template//templatefunctiontovoidf(constT¶m)//becalled{}std::vectorcreateVec()//factoryfunction{std::vectorvw;Widgetw;vw.pus

c++ - 为什么这个用于检测类型 T 是否具有 void operator(EDT const&) 的 C++ 特性会失败?

我正在尝试使用SFINAE来检测作为模板参数T传递的类型是否具有T::operator()(Pconst&),其中P也是模板参数。我在MemberDetectorIdiom的这个例子之后为我的解决方案建模不幸的是,我无法让它为operator()工作,即使我可以让它为普通方法工作。下面是一些演示我面临的问题的示例代码:#include#include#include#includeusingnamespacestd;structhas{voidoperator()(intconst&);};structhasNot1{voidoperator()(int);};structhasNot

c++ - "Control reaches end on non-void function"with do { 返回结果; } 而(条件);

我有以下功能(简化示例):QByteArrayDecompressBytes(constQByteArray&content){/*functionbody(withotherreturnexpressions)*/do{returncontent;}while(content.size()!=0);}添加最后一行用于测试,替换使用的宏。VisualStudio没有发现此代码有问题,但g++生成了warning:controlreachesendofnon-voidfunction[-Wreturn-type]将最后一行更改为returncontent;删除警告。我的问题:为什么编译器