Error message: name lookup of ‘jj’ changed for ISO ‘for’ scoping, (if you use ‘-fpermissive’ G++ will accept your code)

前端 未结 4 1143
谎友^
谎友^ 2021-01-02 10:28

The error is:

In function ‘int returnShortestWeightedBranch(std::vector >*)’:
error: name lookup of ‘jj’ changed for         


        
相关标签:
4条回答
  • 2021-01-02 10:35

    You have a semicolon at the end of the inner for statement. That ends the scope of jj there, so it is not visible inside the block.

    Edit
    You have solved the scope problem, but still have your for loop executing just

    <nothing>;
    

    Remove the semicolon after the parenthesis!

    0 讨论(0)
  • 2021-01-02 10:35

    Some compilers may not accept the use of the variable 'jj' after the for loop is ended. Since the variable is declared inside the for loop, it is destroyed right after it is executed. Thus when you declare your iteration variable outside the for loop it remains there for further use.

    In reality it doesn't work like that and that's why you can force the compiler to ignore the error by adding '-fpermissive'.

    0 讨论(0)
  • 2021-01-02 10:56

    False: for(...;...;...;);

    True: for(...;...;...;)

    You shouldn't use a semicolon, ;

    0 讨论(0)
  • 2021-01-02 10:57
    for (int jj = 0; jj < routeVector[i].selectedBranchesVector.size(); jj++);
    

    This line ends with a semicolon! It shouldn't :)

    0 讨论(0)
提交回复
热议问题