Visual C++ 错误 C2143:语法错误:缺少 ')' 在“恒定”之前

发布于 2024-07-16 06:14:14 字数 443 浏览 4 评论 0原文

我在 Visual C++ 中遇到一个错误,这让我非常困难。

错误是错误c2143阅读:语法错误:在“常量”之前缺少“)”

我的代码行是:

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

我在文件的开头有#include,它应该定义floor(double)函数。

对变量的更多解释。

双深度是该行所在类的成员变量。
int i 是递增索引值。
double t 是一个递增值。

他们做什么并不重要,但我想澄清一下,这三个都已经被定义为基本类型的变量。

我已经检查并验证所有括号都匹配。 我有点不知道编译器指的是什么“常量”。 有任何想法吗?

I'm getting an error in Visual C++ that is giving me a really hard time.

The error is error c2143 reading: syntax error: missing ')' before 'constant'

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.

a bit more explanation of the variables.

double depth is a member variable of the class which this line can be found in.
int i is an incrementing index value.
double t is an incrementing value.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

祁梦 2024-07-23 06:14:14

我不太确定这是否与编译器给您的错误相同,但是您必须在第二个“2”前面放置一个“*”符号,以便:

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

变成这样:

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

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:

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);
盛夏尉蓝 2024-07-23 06:14:14

其他海报已经向您展示了语句中的实际错误,但是请将其分成多个子语句,以更清楚地显示您正在尝试用数学方法做什么,因为如果您不这样做,该函数将来会让您头疼不!

Other posters have shown you the actual error in the statement, but please, split that up into multiple sub-statements that more clearly show what you are trying to do mathematically, because that function is going to cause you headaches in the future if you don't!

此生挚爱伱 2024-07-23 06:14:14
coefficient[i] = (1 - (2 * depth)) + ((t - floor( t + 0.5 ) + 1 ) (the problem is here) 2 * depth);
coefficient[i] = (1 - (2 * depth)) + ((t - floor( t + 0.5 ) + 1 ) (the problem is here) 2 * depth);
梦太阳 2024-07-23 06:14:14

即使你有正确的答案,我也会解释你应该如何得出它。

当在长表达式中遇到无法找到的错误时,请将表达式一点一点地拆开,直到找到它。

在这种情况下:

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

变为:

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

这消除了作为错误源的第一部分。

下一次尝试:

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

最后一次尝试:

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

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.
山人契 2024-07-23 06:14:14

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

coefficient[i] = (1 - (2 * depth)) + ((t - floor( t + 0.5 ) + 1 ) 2(What is 2 doing here?) * depth);

九局 2024-07-23 06:14:14

我在声明枚举时遇到了类似的错误。 这是因为枚举常量之一也在代码的其他地方声明了。

I faced a similar error when declaring an enum. It was because one of the enum constants was also declared elsewhere in the code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文