草庐IT

conversion

全部标签

C++11: "narrowing conversion inside { }"带模数

我尝试在启用gcc和C++11的情况下编译以下代码:unsignedintid=100;unsignedchararray[]={id%3,id%5};我收到这些警告:narrowingconversionof‘(id%3u)’from‘unsignedint’to‘unsignedchar’inside{}[-Wnarrowing]seedemoonline有没有办法帮助编译器发现id%3的结果适合unsignedchar? 最佳答案 在这种特定情况下,使idconst或constexpr将解决问题:constexprunsign

c++ - 海湾合作委员会错误 : invalid conversion from double* to const double

我使用的是gcc4.5.0版。使用下面的简单示例,我假设得到一个错误invalidconversionfromdouble*toconstdouble*#includeusingnamespacestd;voidfoo(constdouble*a){cout为什么编译没有错误?类似的反例如下:#includeusingnamespacestd;voidfoo(constdouble**a){cout(第二个示例的解决方案:将foo定义为foo(constdouble*const*a)。感谢JackEdmonds的评论,这解释了错误消息) 最佳答案

C++ 编译器不会在默认参数结束前警告缺少参数

我用3个参数声明了一个C++函数声明,其中两个参数有这样的默认值。voidfunc(intconstn,boolconstflag=true,int*array=NULL){/*printcontentsofarray*/}当我错误地调用函数时,省略了第二个参数但包括了第三个参数,就像这样intarray[5]={1,2,3,4,5};func(5,array);gcc和intel编译器(Ubuntu14.04LTS上的默认编译器)都没有提示指定了最后一个参数而没有指定倒数第二个参数。代码运行但为数组发送了NULL(我预计代码会失败)。我的问题是为什么编译器没有提示它找不到匹配的函数,

c++ - Sun Studio 12 中的模板编译错误

我们正在迁移到SunStudio12.1和新的编译器[CC:SunC++5.10SunOS_sparc2009/06/03]。我在编译一段代码时遇到编译错误,该代码使用早期版本的SunCompiler[CC:SunWorkShop6update2C++5.32001/05/15]编译良好。这是我得到的编译错误。"Sample.cc":Error:CouldnotfindamatchforLoopThrough(int[2])neededinmain().1Error(s)detected.***Errorcode1.代码:#include#definePRINT_TRACE(STR)\

c++ - "Ambiguous conversion sequence"- 这个概念的目的是什么?

在N465916.3.3.1隐式转换序列中说10Ifseveraldifferentsequencesofconversionsexistthateachconverttheargumenttotheparametertype,theimplicitconversionsequenceassociatedwiththeparameterisdefinedtobetheuniqueconversionsequencedesignatedtheambiguousconversionsequence.Forthepurposeofrankingimplicitconversionsequen

c++ - Qt : After installation of VS2012 LNK1123 failure during conversion to COFF

之后我安装了VS2012我的Qt项目不再编译(我的电脑上有VS2010和VS2012)。消息:LNK1123:转换为COFF期间失败:文件无效或损坏。以前只用VS2010没问题。对于VS2012环境,建议(参见SOhere):使用EnableIncrementalLinkingNO编译卸载.net4.5因为我没有将Qt与VS2012结合使用(所以没有插件),所以我不能setuptheprojectasmentioned.我也不能卸载.net4.5(另一个项目需要)。有机会解决这个问题吗?我有一些相关的问题是否可以针对VS2012C++编译器进行编译?Hereitsays为此,我需要自己

c++ - Boost Program_Options 抛出 "character conversion failed"

我在Ubuntu14.04上,使用CMake和CLion。我正在尝试使用程序选项,以下代码取自其文档中的示例:#include#includeintmain(intac,char*av[]){namespacepo=boost::program_options;usingnamespacestd;po::options_descriptiondesc("Allowedoptions");desc.add_options()("help","producehelpmessage")("compression",po::value(),"setcompressionlevel");po::

c++ - 铿锵错误 : ambiguous conversion for static_cast

我有以下代码:typedefintAliasB;typedefunsignedshortAliasA;classAlias{public:explicitAlias(intsomeInt){}};//(*)!!belowbreakstheconversionpathviaAliasA!!//typedefAliasAliasA;classC{public:C(){}};classB{public:B(){}B(constAliasB&value){}operatorAliasB()const{return-1000;}Ccombine(constB&someB){returnC();}

c++ - 如何使用 C++ TMP 实现 MultiUnitValue 类

我用VC++编写了这个类,这显然不符合标准(TBH似乎很奇怪,标准不允许)如何将其转换为标准C++11?代码:#includetemplateclassMultiUnitValue//Multifornow==2:){constTt;T_to_Uconversion_function;public:MultiUnitValue():t(0){}MultiUnitValue(Tt_):t(t_){}templateVin()const{BOOST_STATIC_ASSERT(0);//"youaretryingtocallinwithtype(unit)notsupported"}tem

c++ - 错误 : invalid conversion from 'void (*)()' to 'void (*)()' -- what?

我正在尝试将回调函数从C++传递到OpenGL(CAPI):gluQuadricCallback(qobj,GLU_ERROR,errorCallback);其中errorCallback是编译为C++代码的文件中的函数,声明为voiderrorCallback();代码在Linux上使用g++4.4编译干净,但在Windows上使用mingw32g++4.4时出现以下错误:..\glwidget.cpp:172:error:invalidconversionfrom'void(*)()'to'void(*)()'..\glwidget.cpp:172:error:initializi