for循环中的逗号
为什么下面的行会产生错误?
for(int i = 0, int pos = 0, int next_pos = 0; i < 3; i++, pos = next_pos + 1) {
// …
}
error: expected unqualified-id before ‘int’
error: ‘pos’ was not declared in this scope
error: ‘next_pos’ was not declared in this scope
编译器是g++。
Why is the following line producing errors?
for(int i = 0, int pos = 0, int next_pos = 0; i < 3; i++, pos = next_pos + 1) {
// …
}
error: expected unqualified-id before ‘int’
error: ‘pos’ was not declared in this scope
error: ‘next_pos’ was not declared in this scope
Compiler is g++.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
每个语句只能有一种类型的声明,因此您只需要一个 int:
You can have only one type of declaration per statement, so you only need one int:
在正常程序中:
永远不会工作并且不被接受。
这就是您在 for 循环中实际尝试做的事情!
In a normal program:
will never work and is not accepted.
This is what you are actually trying to do inside the for loop!