switch “transfer of control bypasses initialization of:” when calling a function

前端 未结 2 1244
长发绾君心
长发绾君心 2020-12-04 21:22

I get a \"transfer of control bypasses initialization of:\" error when i try to build the following switch:

switch (retrycancel)
{
    case 4:    //The user          


        
2条回答
  •  半阙折子戏
    2020-12-04 22:14

    a switch is essentially a goto, that is, it is a goto to the appropriate label. The C++ standard forbids a goto to bypass an initialization of a non-POD object. Take the vector declaration into braces and it will solve the problem

    switch (retrycancel)
        {
         case 4:                //The user pressed RETRY
         {
            std::vector windows = MainHandles().enum_windows().get_results(); //Enumerate all visible windows and store handle and caption in "windows"
            break;
         }
        case 2: 
            //code
        }
    

提交回复
热议问题