错误消息:名称查找“jj”更改为 ISO“for”范围界定,(如果您使用“-fpermissive”G++ 将接受您的代码)

发布于 2024-11-18 13:12:37 字数 1345 浏览 3 评论 0原文

错误是:

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)

代码是:

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

这里可能有什么问题?

编辑 1:

我将以下内容更改为:

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

现在

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

它可以工作了!!我不明白其中的原因。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

黯淡〆 2024-11-25 13:12:37

内部 for 语句末尾有一个分号。这结束了 jj 的范围,因此它在块内不可见。

编辑
您已经解决了范围问题,但仍然执行 for 循环,只需

<nothing>;

删除括号后的分号即可!

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!

时光倒影 2024-11-25 13:12:37
for (int jj = 0; jj < routeVector[i].selectedBranchesVector.size(); jj++);

该行以分号结束!不应该:)

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

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

旧伤慢歌 2024-11-25 13:12:37

某些编译器可能不接受在 for 循环结束后使用变量“jj”。由于该变量是在 for 循环内声明的,因此在执行后它会立即被销毁。因此,当您在 for 循环之外声明迭代变量时,它会保留在那里以供进一步使用。

实际上它并不是这样工作的,这就是为什么你可以通过添加“-fpermissive”来强制编译器忽略错误。

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'.

一江春梦 2024-11-25 13:12:37

错误:for(...;...;...;);

正确:for(...;...;...;)

您不应使用分号,;

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

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

You shouldn't use a semicolon, ;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文