Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

The error is:

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)

The code is:

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;
                }
            }
        }

What can be the problem here?

EDIT 1:

I changed the following:

for (int jj = 0; jj < routeVector[i].selectedBranchesVector.size(); jj++);

to:

int jj;
for (jj = 0; jj < routeVector[i].selectedBranchesVector.size(); jj++);

and now it is working!! I fail to understand the REASONS.

like image 361
Aquarius_Girl Avatar asked Jul 02 '11 10:07

Aquarius_Girl


2 Answers

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!

like image 178
Bo Persson Avatar answered Sep 28 '22 03:09

Bo Persson


for (int jj = 0; jj < routeVector[i].selectedBranchesVector.size(); jj++);

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

like image 42
Kornel Kisielewicz Avatar answered Sep 28 '22 05:09

Kornel Kisielewicz