Visual C++ 错误 C2143:语法错误:缺少 ')' 在“恒定”之前
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我不太确定这是否与编译器给您的错误相同,但是您必须在第二个“2”前面放置一个“*”符号,以便:
变成这样:
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:
Becomes this:
其他海报已经向您展示了语句中的实际错误,但是请将其分成多个子语句,以更清楚地显示您正在尝试用数学方法做什么,因为如果您不这样做,该函数将来会让您头疼不!
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!
即使你有正确的答案,我也会解释你应该如何得出它。
当在长表达式中遇到无法找到的错误时,请将表达式一点一点地拆开,直到找到它。
在这种情况下:
变为:
这消除了作为错误源的第一部分。
下一次尝试:
最后一次尝试:
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:
becomes:
This eliminates the first part as the source of the error.
Next attempt:
Final attempt:
系数[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);
我在声明枚举时遇到了类似的错误。 这是因为枚举常量之一也在代码的其他地方声明了。
I faced a similar error when declaring an enum. It was because one of the enum constants was also declared elsewhere in the code.