initialization of 'element' is skipped by 'case' label

c++, debugging

Solution

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

Problem

I don't understand why I am getting the error: initialization of 'element' is skipped by 'case' label. Can someone please explain to me? ``` void LinkedList::process_example(int choice) { switch(choice) { case 1: cout << endl << endl << "Current S = "; this->printSet(); cout << "Enter an element :"; char* element = "lol"; //cin>>element; cin.clear(); cin.ignore(200, '\n'); this->Addelementfromback(element); //error is here cout << endl << endl << "Current S = "; this->printSet(); break; case 2: this->check_element(); break; case 3: cout << endl << endl; cout << "Current Set S = "; this->printSet(); cout << endl << "S has "; int count = this ->check_cardinality(); cout << count << " elements"; break; } } ```

Original source

Related problems