简体   繁体   English

Visual C ++错误C2143:语法错误:在'常量'之前缺少')'

[英]Visual C++ error C2143: syntax error: missing ')' before 'constant'

I'm getting an error in Visual C++ that is giving me a really hard time. 我在Visual C ++中遇到错误,这让我很难过。

The error is error c2143 reading: syntax error: missing ')' before 'constant' 错误是错误c2143读取:语法错误:在'常数'之前缺少')'

My code line is: 我的代码行是:

coefficient[i] = (1 - (2 * depth)) + ((t - floor( t + 0.5 ) + 1 ) 2 * depth); 

I have #include at the beginning of the file which should define the floor(double) function. 我在文件的开头有#include,它应该定义floor(double)函数。

a bit more explanation of the variables. 对变量的更多解释。

double depth is a member variable of the class which this line can be found in. double depth是可以在其中找到此行的类的成员变量。
int i is an incrementing index value. int i是递增索引值。
double t is an incrementing value. double t是递增值。

What they do is really unimportant, but I wanted to clarify that all three are already defined as variables of basic types. 他们所做的事实上并不重要,但我想澄清一下,这三者都已被定义为基本类型的变量。

I've gone through and verified that all the parentheses match up. 我已经完成并验证所有括号都匹配。 I'm kind of at a loss as to what 'constant' the compiler is referring to. 关于编译器所指的“常量”,我有点不知所措。 Any ideas? 有任何想法吗?

I'm not quite sure if this is the same error that the compiler is giving you, but you have to put a '*' sign in front of the second '2' so that this: 我不太确定这是否与编译器给你的错误相同,但是你必须在第二个'2'前加一个'*'符号,这样:

coefficient[i] = (1 - (2 * depth)) + ((t - floor( t + 0.5 ) + 1 ) 2 * depth);

Becomes this: 变成这样:

coefficient[i] = (1 - (2 * depth)) + ((t - floor( t + 0.5 ) + 1 ) * 2 * depth);

其他海报已经向您展示了声明中的实际错误,但是请将其拆分为多个子语句,以便更清楚地显示您尝试以数学方式进行的操作,因为如果您不这样做,该功能将在未来引起您的头痛“T!

coefficient[i] = (1 - (2 * depth)) + ((t - floor( t + 0.5 ) + 1 ) (the problem is here) 2 * depth);

Even though you have the right answer, I'm going to explain how you should have arrived at it. 即使你有正确的答案,我也会解释你应该如何应对它。

When faced with an error in a long expression that you can't find, take the expression apart, piece by piece, until you find it. 当遇到无法找到的长表达式中的错误时,请将表达式逐个分开,直到找到它为止。

In this case: 在这种情况下:

coefficient[i] = (1 - (2 * depth)) + ((t - floor( t + 0.5 ) + 1 ) 2 * depth);

becomes: 变为:

firsthalf = (1 - (2 * depth));
secondhalf = ((t - floor( t + 0.5 ) + 1 ) 2 * depth);   // Error appears on this line
coefficient[i] = firsthalf + secondhalf;

This eliminates the first part as the source of the error. 这消除了第一部分作为错误的来源。

Next attempt: 下一次尝试:

exprA = (t - floor( t + 0.5 ) + 1 );
exprB = exprA * 2;
exprC = exprB * depth;   // Hmm.... this all worked.  Start putting it back together.
secondhalf = exprC;

Final attempt: 最后的尝试:

exprA = (( MY_TEST_CONSTANT ) 2 * depth);   // Error now becomes obvious.

系数[i] =(1 - (2 *深度))+((t - floor(t + 0.5)+ 1) 2(这里有2个做什么?) *深度);

I faced a similar error when declaring an enum. 在声明枚举时我遇到了类似的错误。 It was because one of the enum constants was also declared elsewhere in the code. 这是因为其中一个枚举常量也在代码中的其他地方声明。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Visual C ++错误C2143:语法错误:缺少&#39;;&#39; 在“恒定”之前 - Visual C++ Error C2143: syntax error : missing ';' before 'constant' 错误C2143:“常量”前缺少语法错误“)” - error C2143: syntax error missing ')' before 'constant' C ++:错误C2143:语法错误:缺少&#39;;&#39; 在“ &lt;”之前 - C++: error C2143: syntax error : missing ';' before '<' Windows Visual C++ 2019 试图传递预处理器变量(linux 中的-D)错误 C2143:语法错误:缺少';' 在“常数”之前 - Windows Visual C++ 2019 trying to pass preprocessor varible (-D in linux ) error C2143: syntax error: missing ';' before 'constant' C2143:语法错误:缺少&#39;;&#39; 在“ *”之前 - C2143: syntax error : missing ';' before '*' 错误c2143缺少&#39;;&#39; &#39;&gt;&gt;&#39;之前,错误c2143缺少&#39;;&#39; 在Visual Studio 2005中C和C ++中的cin和cout之前为&#39;&lt;&lt;&#39; - error c2143 missing ';' before '>>' and error c2143 missing ';' before '<<' for cin and cout in c++ in visual studio 2005 错误C2143:缺少语法错误:缺少&#39;;&#39; 在“ *”之前 - error C2143: missing syntax error: missing ';' before '*' 错误C2143:语法错误:缺少&#39;;&#39; 在``template &lt;&#39;&#39;之前 - error C2143: syntax error : missing ';' before ''template<'' 错误C2143:语法错误:缺少';'在'__stdcall'之前 - error C2143: syntax error : missing ';' before '__stdcall" 错误 C2143:语法错误:缺少“;” 在“如果”之前 - error C2143: syntax error : missing ';' before 'if'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM