Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix C++ error: expected unqualified-id

Tags:

c++

I'm getting this error on line 6:

error: expected unqualified-id before '{' token 

I can't tell what's wrong.

#include <iostream>  using namespace std;  class WordGame; {               // <== error is here on line 6 public:      void setWord( string word )     {         theWord = word;     }     string getWord()     {         return theWord;     }     void displayWord()     {         cout << "Your word is " << getWord() << endl;     } private:     string theWord; }   int main() {     string aWord;     WordGame theGame;     cin >> aWord;     theGame.setWord(aWord);     theGame.displaymessage();  } 
like image 261
Seb Avatar asked Apr 13 '12 04:04

Seb


People also ask

What is unqualified id IN C Plus Plus?

1 Answer. +2. Can be due to different reasons. Something like class Test; // note the semicolon { }; in the global scope will give you unqualified id error before '{' since in the global scope a standalone {} makes no sense, but the samething works fine in local scope as it will be treated as an empty block scope.

What does expected unqualified id before while mean?

Your code is missing a int main(void) function in which all of your code should be inside. By definition, a C++ program is required to have a int main(void) function. You need to put all your code inside the int main(void) function.

What is expected unqualified id before numeric constant?

expected unqualified-id before numeric constantCython is a tool to wrap C/C++ code so that it can interface with a Python interpreter. Cython generates the wrapping code and sends it to GCC.


1 Answers

There should be no semicolon here:

class WordGame; 

...but there should be one at the end of your class definition:

... private:     string theWord; }; // <-- Semicolon should be at the end of your class definition 
like image 56
Alex Z Avatar answered Sep 21 '22 04:09

Alex Z