草庐IT

concatenated_value

全部标签

C++ 模板 : Select different type based on value of template parameter

如何在C++中完成以下操作,这些事情叫什么?templateclassNuclearPowerplantControllerFactoryProviderFactory{//ifS==truetypedefintdata_t;//ifS==falsetypedefunsignedintdata_t;}; 最佳答案 按特化:templateclassFoo;templateclassFoo{typedefintdata_t;};templateclassFoo{typedefunsignedintdata_t;};您可以选择将这两种情

c++ - g++ 警告 : conversion to uint16_t from int may alter its value

根据高级SO用户的建议,我最近开始使用-Wconversion进行编译。在我的代码库上标记。这产生了很多警告,其中一些是合法的(例如,不必要地添加signed和unsigned类型),但也产生了一些令人头疼的警告,如下所示:#includeintmain(){uint16_ta=4;uint16_tb=5;b+=a;return0;}当我用g++-Wconversion-std=c++11-O0myFile.cpp编译时,我明白了warning:conversionto'uint16_t{akashortunsignedint}'from'int'mayalteritsvalue[-W

c++ - g++ 警告 : conversion to uint16_t from int may alter its value

根据高级SO用户的建议,我最近开始使用-Wconversion进行编译。在我的代码库上标记。这产生了很多警告,其中一些是合法的(例如,不必要地添加signed和unsigned类型),但也产生了一些令人头疼的警告,如下所示:#includeintmain(){uint16_ta=4;uint16_tb=5;b+=a;return0;}当我用g++-Wconversion-std=c++11-O0myFile.cpp编译时,我明白了warning:conversionto'uint16_t{akashortunsignedint}'from'int'mayalteritsvalue[-W

c++ - C++ 实现中 "invalid pointer value"转换的文档

根据C++标准,每个实现都必须记录“实现定义的行为”:1.3.11[defns.impl.defined]implementation-definedbehaviorbehavior,forawell-formedprogramconstructandcorrectdata,thatdependsontheimplementationandthateachimplementationdocuments并且读取无效的指针值具有实现定义的行为(参见4.1左值到右值的转换[conv.lval]):iftheobjecttowhichtheglvaluereferscontainsaninva

c++ - C++ 实现中 "invalid pointer value"转换的文档

根据C++标准,每个实现都必须记录“实现定义的行为”:1.3.11[defns.impl.defined]implementation-definedbehaviorbehavior,forawell-formedprogramconstructandcorrectdata,thatdependsontheimplementationandthateachimplementationdocuments并且读取无效的指针值具有实现定义的行为(参见4.1左值到右值的转换[conv.lval]):iftheobjecttowhichtheglvaluereferscontainsaninva

c++ - typedef'ing enum 不会使 enum-values 可见

我有一个类,其中有一个枚举,定义如下:classX{public:enumDirection{DIR_LEFT,DIR_RIGHT};};现在我希望在另一个类中重用这个枚举,如下所示:classY{public:typedefX::DirectionDirection;};正如预期的那样,使用Y::Direction可以正常工作,例如:voidmyFunction(Y::Directiondir){}但枚举中的值似乎没有与typedef一起“复制”。如果我编写以下内容,则会出现编译错误:myFunction(Y::DIR_LEFT);相反,我不得不再次引用枚举的原始位置,像这样:myF

c++ - typedef'ing enum 不会使 enum-values 可见

我有一个类,其中有一个枚举,定义如下:classX{public:enumDirection{DIR_LEFT,DIR_RIGHT};};现在我希望在另一个类中重用这个枚举,如下所示:classY{public:typedefX::DirectionDirection;};正如预期的那样,使用Y::Direction可以正常工作,例如:voidmyFunction(Y::Directiondir){}但枚举中的值似乎没有与typedef一起“复制”。如果我编写以下内容,则会出现编译错误:myFunction(Y::DIR_LEFT);相反,我不得不再次引用枚举的原始位置,像这样:myF

c++ - 当您在检索到的值的表达式上进行分支时,是否有像 `if (Value * value = getValue())` 这样的习语?

我经常用普通的if(Value*value=getValue()){//dosomethingwithvalue}else{//handlelackofvalue}现在,我也经常这样做QStringerror=someFunctionReturningAnErrorString(arg);if(!error.isEmpty()){//handletheerror}//emptyerrormeans:noerror这很好,但我希望error变量的范围为if-block。有一个很好的成语吗?显然,我可以将整个部分包裹在另一个block中。这显然行不通:if(QStringerror=som

c++ - 当您在检索到的值的表达式上进行分支时,是否有像 `if (Value * value = getValue())` 这样的习语?

我经常用普通的if(Value*value=getValue()){//dosomethingwithvalue}else{//handlelackofvalue}现在,我也经常这样做QStringerror=someFunctionReturningAnErrorString(arg);if(!error.isEmpty()){//handletheerror}//emptyerrormeans:noerror这很好,但我希望error变量的范围为if-block。有一个很好的成语吗?显然,我可以将整个部分包裹在另一个block中。这显然行不通:if(QStringerror=som

c++ - 汇编如何做参数传递: by value,引用,不同类型/数组的指针?

为了了解这一点,我编写了这个简单的代码,其中我只是创建了不同类型的变量,并通过值、引用和指针将它们传递给函数:inti=1;charc='a';int*p=&i;floatf=1.1;TestClasstc;//has2privatedatamembers:inti=1andintj=2函数体留空,因为我只是在查看参数是如何传入的。passByValue(i,c,p,f,tc);passByReference(i,c,p,f,tc);passByPointer(&i,&c,&p,&f,&tc);想看看这对数组有何不同,以及如何访问参数。intnumbers[]={1,2,3};pass