草庐IT

constant-expression

全部标签

c++ - C++ : "expected primary-expression before ‘>’ token"中的两个模板

这个问题在这里已经有了答案:WhereandwhydoIhavetoputthe"template"and"typename"keywords?(8个答案)关闭7年前。最小工作示例:#includestructPrinter{templatestaticvoidprint(Telem){std::coutstructMain{templatevoidprint(Telem){//Inthiscase,thecompilercouldguessTfromthecontext//Butinmycase,assumethatIneedtospecifyT.printer_t::print(e

c++ - 警告 : Comparison between signed and unsigned integer expression

我在codepad.org上运行以下代码时出现此错误。“在成员函数‘doubleXchange::getprice(std::string)’中:第87行:警告:有符号和无符号整数表达式之间的比较”这是我的代码:#include#include#includeusingnamespacestd;classXchange{public:Xchange();//doesnothing(?)doublegetprice(stringsymbol);private:vectorstocks;};doubleXchange::getprice(stringsymbol){for(inti=0;i

c++ - 哪个是更好的做法 : global constant or #define?

这个问题在这里已经有了答案:关闭11年前。PossibleDuplicate:C++-enumvs.constvs.#define在使用#define之前,我曾在主函数中创建常量并将它们传递到需要的地方。我发现我经常传递它们,这有点奇怪,尤其是数组大小。最近我一直在使用#define,因为我不必将main中的常量传递给每个单独的函数。但现在我想到了,我也可以使用全局常量,但出于某种原因我一直对它们有点犹豫。哪个是更好的做法:全局常量或#define?还有一个相关的附带问题:如我所描述的那样从我的main传递常量是一种不好的做法吗?

c++ - 错误 : expected primary-expression before ‘>’ : templated function that try to uses a template method of the class for which is templated

这个问题在这里已经有了答案:WhereandwhydoIhavetoputthe"template"and"typename"keywords?(8个答案)关闭8年前。在使用模板和仿函数(未出现在这个问题中)时,我最终遇到了以下简化的问题。以下代码(也可用here)classA{public:templateboolisGood(intin)const{constTf;returninbooltryEvaluator(T&evaluator,intvalue){returnevaluator.isGood(value);}intmain(intargc,constchar*argv[]

c++ - 错误 C2059 : syntax error 'constant'

这个问题在这里已经有了答案:WhyamIgetting"error:expected'}'"inC++butnotinC?(3个答案)关闭9年前。我在头文件中有以下代码:enum{false,true};我在main.c中有我的主要功能。如果我将扩展名更改为main.cpp我收到以下错误:ErrorC2059:syntaxerror'constant'我使用的是VisualC++,知道为什么吗?

C++11 统一初始化 : Field initializer is not constant

我正在尝试像这样实例化一组字符串:classPOI{public:...staticconststd::setTYPES{"restaurant","education","financial","health","culture","other"};...}现在,当我这样做时,我得到了这些错误(全部在这一行):error:fieldinitializerisnotconstantstaticconststd::setTYPES{"restaurant","education","financial","health","culture","other"};error:in-class

java - 'Conditional expressions can be only boolean, not integral.' 是什么意思?

“条件表达式只能是boolean值,不能是整数。”是什么意思?意思?我不知道Java,我知道C++deffenetly不足以理解它的含义。请帮助(在比较C++和Java项目7子项目1中的http://www.javacoffeebreak.com/articles/thinkinginjava/comparingc++andjava.html中找到) 最佳答案 这意味着您需要一个boolean值作为条件,从整数类型的转换不会是隐式的。而不是if(x)你需要if(x!=0)等前者是一个int,在C++中将隐式转换为bool(通过!=0

节点找不到模块-express.js

我有ASP.NET背景。我正在尝试使用ASP.NET中的MVC逻辑来理解Node.js的“路由”逻辑。例如,在我的global.js中,有一个ajax调用/用户/用户列表(我不知道它是什么,它是MVC中的控制器)。我正在尝试使用以下代码与该控制器联系,但我明白了:得到http://localhost:3000/user/userList404(找不到)我应该怎么做才能摆脱这一点?谢谢。这是app.js(完整):varexpress=require('express');varpath=require('path');varfavicon=require('serve-favicon');var

c++ - Visual Studio : C++ newline constant error

在Qt项目(使用Qt插件)上使用VisualStudio,似乎总是会抛出一条错误消息:errorC2001:newlineinconstant来自以下行:this->setApplicationVersion(QString(BUILD_VERSION));或者每当我使用在我的QMake文件中定义的编译器常量时。BUILD_VERSION在我的QMake构建配方中定义,如果我使用不同的IDE编译项目会成功(即使我使用相同的MSVC编译器,一切正常)。我想我要么在Qt插件中或在VisualStudio中缺少首选项,要么我需要在我的QMake文件等之外重新定义我的常量......常量由In

c++ - 有没有办法绕过 "This expression has side effects and will not be evaluated."?

在VisualStudio2017中,我创建了一个调用C++函数的.natvis调试器可视化规则。在调试器中显示:这个表达式有副作用,不会被计算。除此之外,它还显示了一个蓝色的小箭头,可以单击该箭头以强制其求值,然后它实际上会调用该函数。(我认为这可能是最近的一个功能,因为我似乎记得在VS2013中尝试过这个并且不记得它有绕过)我的问题是:有没有什么方法可以永久绕过这个安全检查,让它总是立即评估我的功能,而不需要我点击箭头?我看过一个非常相似的问题:"Thisexpressioncausessideeffectsandwillnotbeevaluated".Howtosuppress?