initialization of 'element' is skipped by 'case' label [duplicate]
Try wrap case
with {}
, and put all your statement inside {}
.
case 1:
{
cout << endl << endl << "Current S = ";
this->printSet();
// and other mess
}
break;
You should put all these statement in functions, keep case
statement clear. For example, write this style:
case 1:
initializeElement();
break;
case 2:
doSomethingElse();
break;
See link
When a variable is declared in one case
, the next case
is technically still in the same scope so you could reference it there but if you hit that case
without hitting this one first you would end up calling an uninitialised variable. This error prevents that.
All you need to do is either define it before the switch
statement or use curly braces { }
to make sure it goes out of scope before exiting a specific case
.