草庐IT

constantly

全部标签

c++ - cppcheck 认为我有 "Redundant code: Found a statement that begins with numeric constant"

Cppcheck(version1.46.1)对像这样的枚举发出以下警告:enumDATABASE_TYPE{DATABASE_TYPE_UNKNOWN=-1,//Redundantcode:Foundastatementthatbeginswithnumericconstant我不认为这是多余的。能够做那样的事情非常重要。这是cppcheck的错误还是我没有看到什么?更新我设法将它归结为一个最小的例子。这因为cppcheck有2个(更多)错误而变得复杂,这使得我的减少看起来没有效果。共有5个文件:a.h、a.cpp、b.h、b.cpp和inc。h包含以下内容。VC9在没有警告的情况下

c++ - std::regex_constants::optimize 使用的优化技术

我正在使用std::regex,在阅读std::regex_constants中定义的各种常量时,我​​遇到了std::optimize,阅读它,听起来它在我的应用程序中很有用(我只需要一个正则表达式实例,在开始时初始化,但在整个加载过程中多次使用它)。根据workingpapern3126(第1077页),std::regex_constants::optimize:Specifiesthattheregularexpressionengineshouldpaymoreattentiontothespeedwithwhichregularexpressionsarematched,a

c++ - clang 中 regex_constants 的错误实现?

如standard中所述:match_prev_avail:--first是一个有效的迭代器位置。设置后,会导致match_not_bol和match_not_bow被忽略但我运行以下代码并得到:#include#includeusingnamespacestd;intmain(){regexre0("^bcd");stringstr="abcd";std::string::iteratorstart=str.begin()+1;cout输出:010match_prev_avail似乎被match_not_bol覆盖了。 最佳答案

c++ - std::integral_constant 背后的原因是什么?

它的实际用例是什么?std::integral_constant我可以理解这是一个值为2的包装器:typedefstd::integral_constanttwo_t但为什么不直接使用2或用2定义一个constint值呢? 最佳答案 在少数情况下std::integral_constant非常有用。其中之一是标签分发。例如,std::true_type和std::false_type只是std::integral_constant和std::integral_constant分别。每个typetrait源自std::true_typ

c++ - 为什么使用静态 "constants"而不是实际值?

关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭5年前。Improvethisquestion我正在查看最小二乘法的代码,我遇到了以下几行:staticdoubleone=1.0;staticdoublep1=0.1;staticdoublep5=0.5;...我想知道为什么有人会为1.0定义一个static。例如,我可以理解pi有一些东西,但是对于1.0和0.1等微不足道的数学值?我认为这会降低代码的可读性,但它可能还有一些我遗漏的其他好处。那么,这些定义有原因吗?或者,如果它没

c++ - 什么是 "symbolic constants"和 "magic constants"?

在BjarneStroustrup的ATourofC++中,每章末尾都列出了一些建议。在第一章的结尾,其中一个写道:Avoid‘‘magicconstants;’’usesymbolicconstants;什么是魔法常量和符号常量? 最佳答案 somethingElse=something*1440;//amagicconstantsomethingElse=something*TWIPS_PER_INCH;//asymbolicone第一个是魔法常量的例子,它除了它的值之外没有传达任何其他信息。后者更有用,因为意图很明确。如果您有

c++ - 为什么是非法的: copying vector of pointers into a vector of pointers to constants

问题以下代码无法在C++11(或C++14)中编译。我理解编译器的错误输出,但为什么标准不允许?//main.cpp#includeintmain(void){doublea=3.0;doubleb=3.0;//Itworkswithmerepointersconstdouble*ptrToConst=&a;/***/double*ptrToObj=&a;//ptrToObj=ptrToConst;//Illegal:that'sunderstandable…ptrToConst=ptrToObj;//Works//Butthesamedoesn'tworkwithvectorstop

c++ - 使用模板时得到 "cannot appear in a constant-expression"

templateclassCAT{};intmain(){inti=10;CATcat;return0;//hereIgoterror:‘i’cannotappearinaconstant-expression}甚至inti=10;constintj=i;CATcat;//thisstillcannotwork但我已经将i转换为constint,为什么编译器仍然报错?我的平台是ubuntu,gcc版本4.4.3谢谢,==============感谢大家的意见,但在某些情况下,我需要一个非常量变量,例如://alloperations.henumOPERATIONS{GETPAGE_FR

c++ - 编译器错误 "character constant too long for its type"。怎么了?

我有一些我正在尝试处理的代码...#include#includeintmain(){std::cout";std::stringchoice;std::getline(cin,choice);if(choice=='hamburger'||choice=='Hamburger'){std::cout";std::stringopt;std::getline(cin,opt);if(opt=='y'||opt=='Y'||opt=='yes'||opt='Yes'){std::cout这是改编self编写的Bash脚本,是我的第一个C++程序之一。当我编译它时,它出现了这些错误...t

c++ - 模板编译失败 : 'double' is not a valid type for a template constant parameter

templateclassLowerBoundedType{};templateclassvectorelement{};templateclassvectorelement{typedefLowerBoundedTypetype;};有错误:error:'double'isnotavalidtypeforatemplateconstantparameter 最佳答案 唯一对非类型模板参数有效的数字类型是整数和枚举。因此,您不能拥有double类型的非类型模板参数。 关于c++-模板编译