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(); }
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With