I get a “transfer of control bypasses initialization of:” error when i try to build the following switch:
switch (retrycancel)
{
case 4: //The user pressed RETRY
//Enumerate all visible windows and store handle and caption in "windows"
std::vector<MainHandles::window_data> windows = MainHandles().enum_windows().get_results();
break;
case 2:
//code
}
It has something to do with my calling my enumerate function. If it is not allowed to call a function from within a switch, is there a workaround for this kind of problem?
section 6.6.4 of the C++ standard:
section 6.7 of the C++ standard:
Emphasis added by me. Since
switchis reallygotoin disguise, you’re encountering this behavior. To solve this, add braces if you must use aswitchor refactor into
if/elseThough it’s not obvious to me what you’re hoping to accomplish with creating the
windowsvectorinside aswitch, so you may want to rethink your design. Note I added aconstqualifier towindowssince it’s not modified in your example.