Goto out of a block: do destructors get called?

后端 未结 4 746
陌清茗
陌清茗 2020-12-28 12:14

Consider the following code:

void foo()
{
    {
        CSomeClass bar;

        // Some code here...

        goto label;

        // and here...
    }

lab         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-28 12:46

    1) Yes. 2) Don't do this.

    Elaboration: conceptually, this is no different from leaving a loop via a break. goto, however, is strongly, strongly discouraged. It is almost never necessary to use goto, and any use should be scrutinized to find out what's going on.

提交回复
热议问题