【发布时间】:2025-11-30 23:50:01
【问题描述】:
为什么以下行会产生错误?
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++。
【问题讨论】:
-
相关:*.com/questions/3337126/… 似乎引用了较早的 *.com/questions/2340073/…,这对于 this 问题来说似乎是很好的重复。
标签: c++ for-loop comma-operator