0

I am working on a project for one of the classes on Udemy.com and keep getting this error;

/home/scott/bullcowgame/src/main.cc:40:3: error: ‘constexpr’ was not declared in this scope /home/scott/bullcowgame/src/main.cc:40:13: error: expected ‘;’ before ‘int’ /home/scott/bullcowgame/src/main.cc:42:35: error: ‘WORD_LENGTH’ was not declared in this scope

this is my code

 #include <iostream> #include <string> using namespace std; void PrintIntro(); string GetGuessAndPrintBack(); // the entry point for our application int main() { PrintIntro(); GetGuessAndPrintBack(); GetGuessAndPrintBack(); cout << endl; return 0; } // introduce the game void PrintIntro() { constexpr int WORD_LENGTH = 9; cout << "Welcome to Bulls and Cows, a fun word game.\n"; cout << "Can you guess the " << WORD_LENGTH; cout << " letter isogram I'm thinking of?\n"; cout << endl; return; } // get a guess from the player string GetGuessAndPrintBack() { cout << "Enter your guess: "; string Guess = ""; getline(cin, Guess); // print the guess back cout << "Your guess was: " << Guess << endl; return Guess; } 

I am using the Anjuta IDE

2
  • 5
    ‘constexpr’ was not declared in this scope. Compile with C++11 enabled. Commented May 22, 2017 at 0:36
  • constexpr Commented May 22, 2017 at 0:39

2 Answers 2

1

It seems your compiler does not support constexpr. You should check if your compiler supports it with a flag (ie the default standard used for compilation is older than C++11).

Otherwise you will have to download one that supports it (or give up using constexpr). GCC will support it if you're not on Windows. For Windows, I guess Cygwin/Mingwin support it but I don't know for sure. Clang should support it on all platforms.

Sign up to request clarification or add additional context in comments.

1 Comment

GCC supports it on Windows, unless you are talking about obsolete versions
0

If you are using code blocks go to settings > compiler > compiler settings and check the c++11 option It works for me https://i.sstatic.net/qIYtB.jpg

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.