草庐IT

void_type

全部标签

c++ - GCC 选项 : warning on non-void functions without a return statement

如果存在具有非空返回值但在其定义中不包含return语句的函数,是否有生成错误/警告的GCC/g++选项?例如:intadd(inta,intb){a+b;} 最佳答案 -Wreturn-type.它由-Wall(您应该始终与-Werror-Wextra一起运行)启用。 关于c++-GCC选项:warningonnon-voidfunctionswithoutareturnstatement,我们在StackOverflow上找到一个类似的问题: https:

c++ - 错误 : ‘i’ does not name a type with auto

这个问题在这里已经有了答案:HowdoIenableC++11ingcc?(4个答案)关闭7年前。我是C++新手,这是我的程序#include#include#include#include#includeintmain(){staticconstdoublearr[]={16.0,2.2,77.5,29.0,24.0};std::vectorvec(arr,arr+sizeof(arr)/sizeof(arr[0]));std::transform(vec.begin(),vec.end(),vec.begin(),bind2nd(std::minus(),3.0));for(aut

c++ - C++ 与 C 中函数调用中的 void 指针

我有一段代码可以在C中运行,但不能在C++中运行,是否有任何方法可以让它在C和C++上运行?voidfoo(void*b){int*c=b;printf("%d\n",*c);}intmain(){inta=1000;foo(&a);return0;}输出:C++:1Infunction'voidfoo(void*)':2Line3:error:invalidconversionfrom'void*'to'int*'3compilationterminateddueto-Wfatal-errors.C:1000请帮忙 最佳答案 in

c++ - 从 std::array 等获取 size_type 的惯用方法

由thisquestion触发,我想出了以下代码(在我的回答中是boost::array,但同样适用于std::array):template::size_typesize>voidDataTransform(std::arraydata){}我对::size_type一点都不满意.我必须以一定的大小进行实例化,才能知道size_type.对于std::array我本可以使用size_t,那么一般情况呢?如果size_type怎么办不是size_t?或者更一般的(即不适用于std::array)如果size_type怎么办?不同的尺寸是不同的(愚蠢但可能)?我知道这个问题相当学术,有很

c++ - 错误 : '...' does not name a type

我有一个工作项目。重新安排一些代码后,我尝试重新编译我的项目,然后奇怪的事情开始发生。查看编译器输出的这段摘录。我正在使用MinGWG++从Windows上的Eclipse进行编译。****BuildofconfigurationDebugforprojectPract2********InternalBuilderisusedforbuild****g++-O0-g3-Wall-c-fmessage-length=0-omove.o..\move.cppInfileincludedfrom..\/game.h:11:0,from..\/piece.h:10,from..\/move.

c++ - 在 C++11 的模板化函数中处理 void 变量

我有一个模板类,它必须在调用一个参数和返回类型都是通用的函数之前执行一些操作。这是方法:templateReturnTypefunction(Args...args){//prepareforcall//...ReturnTyperv=makeCall(args...);//[1]//dismissthecall//...returnrv;}当然在ReturnType时编译正确不是void.当我在这种情况下使用它时:function(firstArg,secondArg);编译器响应error:return-statementwithavalue,infunctionreturning

c++ - 我如何取回此 void* 的值?

我有一个空指针,我可以很好地设置它的值(至少我认为我做对了)。但是当我试图获取存储在那里的值时,我什么也得不到。void*指向字符串或int或其他任何内容都没有关系。我在这里缺少什么?classVertex2{public:int_id;void*_data;templateTgetData(){T*value=(T*)_data;return*value;}templatevoidsetData(Tdata){_data=&data;}}; 最佳答案 voidsetData(Tdata)接收data按值。因此,设置指向data的指

为什么我遇到错误:attributeError:'int'对象没有属性'type'

我正在将LLVMlite与Pyvex结合使用。我已经在llvmlite中定义了一些功能,如下所示:defint32(val):returnir.Constant(ir.IntType(32),val)defput64(putoffset,val):llvmtmp=builder.gep(regtag,(int32(0),int32(putoffset)),True)returnbuilder.store(val,llvmtmp)但是,当我想使用以下代码调用此函数时:forstmtinirsb.statements:ifisinstance(stmt,pyvex.IRStmt.Put):puto

c++ - void ** 相当于 void * 返回?

void*alligned_malloc(size_tbytes,uint16_tallign){uint16_toffset=allign-1+sizeof(void*);void*p1=malloc(offset+bytes);void**p2=(void**)(((size_t)p1+offset)&~(allign-1));p2[-1]=p1;returnp2;//Whyisthiscorrect?shouldnotthereturnbep2[0]asitisreturningvoid**}请帮助我理解这个修改后的mallocvoid**是如何等同于void*return的?

c++ - "void();"作为单独的语句在 C++ 中意味着什么?

这个程序是如何编译好的?intmain(){void();//Doesthiscreatea"void"objecthere?}我已经在MSVC和GCC下进行了测试。但是void是一个不完整的类型。当您对任何其他不完整的用户定义类型执行相同操作时,classIncomplete;intmain(){Incomplete();//Errorsaying"Incomplete"isincomplete.} 最佳答案 C++11§5.2.3[expr.type.conv]/2详细介绍(强调我的):TheexpressionT(),wher