Was ist dieser Fehler im code?

während der Arbeit im try-catch in rüber kam dieser Fehler. Aber ich kann trace die Ursache für diese Fehlermeldung obwohl ich surfte im Netz und SO.

Mein code ist...

int main()
{
Queue q;
int choice,data;

 while(1)
 {
  choice  = getUserOption();
  switch(choice)
  {
   case 1:
     cout<<"\nEnter an element:";
     cin>>data;
     q.enqueue(data);
     break;
   case 2:
     int element;
     element = q.dequeue();
     cout<<"Element Dequeued:\n"<<element;
     break;
   case 3:
     q.view();
     break;
   case 4:
     exit(EXIT_SUCCESS);
  }
  catch(UnderFlowException e)
  {
   cout<<e.display();
  }
  catch(OverFlowException e)
  {
   cout<<e.display();
  }

 }//end of while(1)

       return 0;
}

Für mich ist alles, in der der obige code scheint richtig zu sein. Aber g++ complier wirft...

muthu@muthu-G31M-ES2L:~/LangFiles/cppfiles/2ndYearLabException$ g++ ExceptionHandlingEdited.cpp
ExceptionHandlingEdited.cpp: In member function void Queue::enqueue(int)’:
ExceptionHandlingEdited.cpp:89:97: warning: deprecated conversion from string constant to char*’
ExceptionHandlingEdited.cpp: In member function int Queue::dequeue()’:
ExceptionHandlingEdited.cpp:113:95: warning: deprecated conversion from string constant to char*’
ExceptionHandlingEdited.cpp: In member function void Queue::view()’:
ExceptionHandlingEdited.cpp:140:66: warning: deprecated conversion from string constant to char*’
ExceptionHandlingEdited.cpp: In function int main()’:
ExceptionHandlingEdited.cpp:185:3: error: expected primary-expression before catch
ExceptionHandlingEdited.cpp:185:3: error: expected ‘;’ before catch
ExceptionHandlingEdited.cpp:189:3: error: expected primary-expression before catch
ExceptionHandlingEdited.cpp:189:3: error: expected ‘;’ before catch
  • Abgesehen von den Antworten, die deprecated conversion from string constant to ‘char*’ ist auch eine wichtige Warnung. Stellen Sie sicher, dass Sie verwenden const char* für string-Literale.
Schreibe einen Kommentar