C++ for循环中的逗号运算符

Abr*_*ile 2 c++ for-loop comma

我试图使用逗号分隔for循环中的多个初始化,但我收到下面的错误.

在for循环的第一部分使用逗号是合法的吗?

error: too few template-parameter-lists
error: sEnd was not declared in this scope


#include <iostream>
#include <algorithm>
#include <vector>    

int main() {
  using namespace std;
  typedef vector<int> Vc;
  Vc v;
  for(Vc::iterator sIt = v.begin(), Vc::iterator sEnd = v.end();
      sIt != sEnd; ++sIt) {
    // do something
  }    
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

App*_*les 6

应该只是:

                                  /* remove this  */
for(Vc::iterator sIt = v.begin(), /* Vc::iterator */ sEnd = v.end();
    sIt != sEnd; ++sIt) {
  // do something
}
Run Code Online (Sandbox Code Playgroud)

变为:

for(Vc::iterator sIt = v.begin(), sEnd = v.end();
    sIt != sEnd; ++sIt) {
  // do something
}
Run Code Online (Sandbox Code Playgroud)

此外,这不是逗号运算符的用法(逗号运算符只能在表达式中使用); 这是一个简单的变量声明.