我不明白为什么我会遇到错误:

“元素"标签跳过了"元素"的初始化。

有人可以向我解释吗?

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;
    }
}

答案

尝试包裹case{},并将您的所有声明都放在里面{}

case 1:
{
   cout << endl << endl << "Current S = ";
   this->printSet();    
   // and other mess
}
break;

您应该将所有这些声明都置于功能中,请保留case声明清除。例如,写下此样式:

case 1:
   initializeElement();
   break;
case 2:
   doSomethingElse();
   break;

关联

来自: stackoverflow.com