Alex Rivera | Logout

Goto out of a block: do destructors get called?

Asked 2010-07-05T13:41:33.083
54

Consider the following code:

void foo()
{
    {
        CSomeClass bar;

        // Some code here...

        goto label;

        // and here...
    }

label:
    // and here...
}

Will the destructor of bar be called ?

Edit
Report

1 Answer

39

Yes, they will be called.

Update: (it's okay to do this, gotos is not worse than throwing dummy exceptions or using bools/ifs to get out of things. A simple goto inside a function don't make it spaghetti code.)

answered 2010-07-05T13:45:24.120

Your Answer