在这个范围内没有声明C++
我正在为Udemy.com上的一个类做一个项目,不断地出现这个错误 /home/scott/bullcowgame/src/main.cc:40:3:错误:“constexpr”未在此范围内声明 /home/scott/bullcowgame/src/main.cc:40:13:错误:应为“;”在“int”之前 /home/scott/bullcowgame/src/main.cc:42:35:错误:“单词长度”未在此范围内声明 这是我的密码在这个范围内没有声明C++,c++,compiler-errors,constexpr,C++,Compiler Errors,Constexpr,我正在为Udemy.com上的一个类做一个项目,不断地出现这个错误 /home/scott/bullcowgame/src/main.cc:40:3:错误:“constexpr”未在此范围内声明 /home/scott/bullcowgame/src/main.cc:40:13:错误:应为“;”在“int”之前 /home/scott/bullcowgame/src/main.cc:42:35:错误:“单词长度”未在此范围内声明 这是我的密码 #include <iostream&
#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;
}
我正在使用Anjuta IDE,您的编译器似乎不支持constexpr。您应该使用一个标志检查编译器是否支持它,即用于编译的默认标准早于C++11 否则,您将不得不下载一个支持它或放弃使用constexpr。 如果您不在Windows上,GCC将支持它。对于Windows,我想Cygwin/Mingwin支持它,但我不确定。
Clang应该在所有平台上都支持它。如果使用代码块,请转到“设置>编译器>编译器设置” 并选中c++11选项 它对我有用
“constexpr”未在此范围内声明。启用C++11进行编译。GCC在Windows上支持它,除非您谈论的是过时的版本