Aqu*_*irl 9 c++ compiler-errors
错误是:
In function ‘int returnShortestWeightedBranch(std::vector<route, std::allocator<route> >*)’:
error: name lookup of ‘jj’ changed for ISO ‘for’ scoping
note: (if you use ‘-fpermissive’ G++ will accept your code)
Run Code Online (Sandbox Code Playgroud)
代码是:
for (int i = 0; i< routeVector.size(); i++)
{
if (routeVector[i].exitPoint == exitPointDetailsVector[preserveL].exitPoint)
{
cout << "\n-----------parent: " << routeVector[i].exitPoint;
branch obj;
obj.connectedExitPoint = exitPointDetailsVector[preserveI].exitPoint;
routeVector[i].selectedBranchesVector.push_back (obj);
for (int jj = 0; jj < routeVector[i].selectedBranchesVector.size(); jj++);
{
cout << "\n-----------branch: " << routeVector[i].selectedBranchesVector[jj].connectedExitPoint;
}
}
}
Run Code Online (Sandbox Code Playgroud)
这可能是什么问题?
编辑1:
我改变了以下内容:
for (int jj = 0; jj < routeVector[i].selectedBranchesVector.size(); jj++);
Run Code Online (Sandbox Code Playgroud)
至:
int jj;
for (jj = 0; jj < routeVector[i].selectedBranchesVector.size(); jj++);
Run Code Online (Sandbox Code Playgroud)
现在它正在工作!! 我不理解原因.
Bo *_*son 22
你在内部for语句的末尾有一个分号.这结束了jj那里的范围,所以它在块内部是不可见的.
编辑
您已解决了范围问题,但仍然只执行了for循环
<nothing>;
Run Code Online (Sandbox Code Playgroud)
括号后删除分号!