<small id='oVzDU'></small><noframes id='oVzDU'>

<legend id='oVzDU'><style id='oVzDU'><dir id='oVzDU'><q id='oVzDU'></q></dir></style></legend>
<i id='oVzDU'><tr id='oVzDU'><dt id='oVzDU'><q id='oVzDU'><span id='oVzDU'><b id='oVzDU'><form id='oVzDU'><ins id='oVzDU'></ins><ul id='oVzDU'></ul><sub id='oVzDU'></sub></form><legend id='oVzDU'></legend><bdo id='oVzDU'><pre id='oVzDU'><center id='oVzDU'></center></pre></bdo></b><th id='oVzDU'></th></span></q></dt></tr></i><div id='oVzDU'><tfoot id='oVzDU'></tfoot><dl id='oVzDU'><fieldset id='oVzDU'></fieldset></dl></div>
<tfoot id='oVzDU'></tfoot>
    • <bdo id='oVzDU'></bdo><ul id='oVzDU'></ul>

      For 循环在它自己的花括号内

      For loop inside its own curly braces(For 循环在它自己的花括号内)
    1. <legend id='E9kGz'><style id='E9kGz'><dir id='E9kGz'><q id='E9kGz'></q></dir></style></legend>
          <tbody id='E9kGz'></tbody>
            <bdo id='E9kGz'></bdo><ul id='E9kGz'></ul>

              1. <tfoot id='E9kGz'></tfoot>
                <i id='E9kGz'><tr id='E9kGz'><dt id='E9kGz'><q id='E9kGz'><span id='E9kGz'><b id='E9kGz'><form id='E9kGz'><ins id='E9kGz'></ins><ul id='E9kGz'></ul><sub id='E9kGz'></sub></form><legend id='E9kGz'></legend><bdo id='E9kGz'><pre id='E9kGz'><center id='E9kGz'></center></pre></bdo></b><th id='E9kGz'></th></span></q></dt></tr></i><div id='E9kGz'><tfoot id='E9kGz'></tfoot><dl id='E9kGz'><fieldset id='E9kGz'></fieldset></dl></div>

                <small id='E9kGz'></small><noframes id='E9kGz'>

                本文介绍了For 循环在它自己的花括号内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我遇到过这种 for 循环布局:

                I have come across this for-loop layout:

                #include <iostream>
                int main()
                {
                    {
                        for (int i = 0; i != 10; ++i)
                        {
                            std::cout << "delete i->second;" << std::endl;
                        }
                    }
                
                    {
                        for (size_t i = 0; i < 20; ++i)
                        {
                            std::cout << "delete m_indices[i];" << std::endl;
                        }
                    }
                    return 0;
                }
                

                我想知道这层额外的牙套是做什么用的?这在我们的代码库中出现了几次.

                I was wondering what this extra layer of braces is for? This appears a few times in our code base.

                推荐答案

                很久很久以前,VS6 存在并且很流行.然而,它不符合许多 C++ 标准;这在当时是合理的,因为它是在标准正式发布之前(同年)发布的;然而,据我所知,它确实遵守了标准草案.

                Once upon a time, many moons ago, VS6 existed and was popular. It failed however to conform to a number of C++ standards; which was reasonable at the time as it was released just before (on the same year) the standard was officially released; it did however adhere to the draft of the standard as far as I'm aware.

                草案和官方标准之间变化的一个标准是第一部分中创建的 for 循环变量的生命周期;导致以下代码无法编译

                One of the standards that changed between the draft and the official standard, was the lifetime of for loop variables created in the first section; leading to the following code failing to compile

                {
                    for (int i=0; i<1; ++i){}
                    for (int i=0; i<2; ++i){}
                }
                

                因为 i 被第二个 for 循环重新定义.

                because i was redefined by the second for loop.

                虽然其他编译器也有这个bug;我强调 VS6 版本,因为它在标准发布后的几年内仍然是 Visual Studio 的唯一版本,但从未针对此特定问题发布更新;这意味着它产生了更显着的影响.

                While other compilers also suffered this bug; I highlight the VS6 one because it remained the only version of visual studio for a number of years after the release of the standard, but never released an update for this particular issue; meaning that it had a more significant impact.

                对此的解决方案是强制整个 for 循环进入其自己的范围,如您所示.

                A solution to this is to force the whole for loop into its own scope as you have shown.

                这篇关于For 循环在它自己的花括号内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Is Type(::x); valid?(是类型(::x);有效的?)
                Difference between an inline function and static inline function(内联函数和静态内联函数的区别)
                Compilation fails randomly: quot;cannot open program databasequot;(编译随机失败:“无法打开程序数据库)
                Too many initializers error for a simple array in bcc32(bcc32 中的简单数组的初始值设定项过多错误)
                No Member named stoi in namespace std(命名空间 std 中没有名为 stoi 的成员)
                Error using a constexpr as a template parameter within the same class(在同一个类中使用 constexpr 作为模板参数时出错)
              2. <tfoot id='O9ptu'></tfoot>

                      <small id='O9ptu'></small><noframes id='O9ptu'>

                      <i id='O9ptu'><tr id='O9ptu'><dt id='O9ptu'><q id='O9ptu'><span id='O9ptu'><b id='O9ptu'><form id='O9ptu'><ins id='O9ptu'></ins><ul id='O9ptu'></ul><sub id='O9ptu'></sub></form><legend id='O9ptu'></legend><bdo id='O9ptu'><pre id='O9ptu'><center id='O9ptu'></center></pre></bdo></b><th id='O9ptu'></th></span></q></dt></tr></i><div id='O9ptu'><tfoot id='O9ptu'></tfoot><dl id='O9ptu'><fieldset id='O9ptu'></fieldset></dl></div>
                      <legend id='O9ptu'><style id='O9ptu'><dir id='O9ptu'><q id='O9ptu'></q></dir></style></legend>
                          <bdo id='O9ptu'></bdo><ul id='O9ptu'></ul>

                            <tbody id='O9ptu'></tbody>