草庐IT

magic-constants

全部标签

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++-模板编译

Java 互操作性 : how to declare a compile-time array constant in Kotlin?

我有这个Javaannotationdeclaration并想在Kotlin中使用它classCurlCommand{Parameter(names="-groups",description="Comma-separatedlistofgroupnamestoberun")vargroups:Array?=null}编译器报告TYPE_MISMATCH必需:kotlin.Array找到:kotlin.String我试过了Parameter(names=Array(1,{i->"-groups"}),description="Comma-separatedlistofgroupname

Java 互操作性 : how to declare a compile-time array constant in Kotlin?

我有这个Javaannotationdeclaration并想在Kotlin中使用它classCurlCommand{Parameter(names="-groups",description="Comma-separatedlistofgroupnamestoberun")vargroups:Array?=null}编译器报告TYPE_MISMATCH必需:kotlin.Array找到:kotlin.String我试过了Parameter(names=Array(1,{i->"-groups"}),description="Comma-separatedlistofgroupname

windows - Windows 上的 mllr_solve 'Error reading byte order magic number'

我正在学习自适应默认声学模型教程,但在运行mllr_solve时遇到错误。INFO:main.c(382):--1.Readinputmean,(var)andaccumulation.ERROR:"pio.c",line434:fread()failed;retrying...:NoerrorERROR:"swap.c",line79:errorwhilereadingbo_magicERROR:"s3io.c",line177:ErrorreadingbyteordermagicnumberERROR:"s3io.c",line265:Errorreadingheaderforen

windows - 避免 Inno Setup 中的 "Failed to expand shell folder constant userdocs"错误

我将一些示例文档安装到Windows上标准“我的文档”文件夹的“PerfectTablePlan”子文件夹中。这适用于99%以上的用户。但是,如果用户没有“我的文档”文件夹,我会收到许多错误消息,形式如下:Internalerror:Failedtoexpandshellfolderconstant“userdocs”这对用户来说不是很鼓舞人心!可以不为这些用户安装示例(或将它们安装在其他地方)。但不要显示丑陋的错误消息。问题似乎来自于{userdocs}的ExpandConstant宏扩展。有没有什么方法可以在不使用宏的情况下获取“我的文档”的路径?或者有什么方法可以抑制错误信息?E

windows - PHP 7.0.5 : Use of undefined constant FTP_BINARY - assumed 'FTP_BINARY'

在WindowsIIS上升级到PHP7.0.5(终于有了sqlsrvPDO驱动程序)。我正在使用Laravel5.1,在尝试连接到FTP驱动器时,我从https://github.com/thephpleague/flysystem/blob/master/src/Adapter/Ftp.php#L19收到以下错误.使用未定义常量FTP_BINARY-假定为“FTP_BINARY”这是一个用于传输的PHP常量,因此应该没有问题,文档中也没有任何内容表明它已被弃用或其他任何内容。FTP_ASCII是一样的。我唯一做的就是更改PHP版本+SQL驱动程序。引用:http://php.net/