[错误]期望在数字常量之前的nonqualified-id [英] [Error] expected unqualified-id before numeric constant
问题描述
我的代码在这里:
my code is here:
#include<iostream>
using namespace std;
#define MAX 100
#define NEWLINE '\n'
#define MIN 0
int main()
{
const int MAX = 100;
const float PI = 3.1415;
const char BELL = '\a';
cout << "MAX = " << MAX << NEWLINE;
cout << "\nBELL" << BELL;
float ds = PI*3*3;
cout << "\nDien tich hinh tron ban kinh 3 la: " << ds << NEWLINE;
return 0;
}
当我编译它时说
4 13 C:\ Users \Administrator \Desktop \Tai lieu hoc lam game\c ++ \ Untitled5.cpp [错误]预期不合格的数字常数之前
我尝试了什么:
我不知道如何修复它。
when i compile it said
4 13 C:\Users\Administrator\Desktop\Tai lieu hoc lam game\c++\Untitled5.cpp [Error] expected unqualified-id before numeric constant
What I have tried:
I don't know how to fix it.
推荐答案
#define MAX 100
#define NEWLINE '\n'
#define MIN 0
int main()
{
// You have defined MAX as 100 above so the following line evaluates to:
// const int 100 = 100; which is not valid
const int MAX = 100;
为什么你定义了 NEWLINE
?你应该使用 ios
常量 endl
来使用 cout $ c $完成一行c>。
Also why have you defined NEWLINE
? You should use the ios
constant endl
to complete a line using cout
.
#define MAX 100
#define MAX 100
const int MAX = 100;
const int MAX = 100;
您正在重新定义 MAX
符号。你必须丢弃这两个定义中的一个。
请注意,在 C ++
,你的常量并不需要 #define
:你最好使用 const
,甚至更好, constexpr
。
You are re-defining the MAX
symbol. You must discard one of the two definitions.
Please note, in C++
, you don't really need the #define
for your constants: you'd better use const
or, even better, constexpr
.
您已将MAX
定义为100.所以line
You have definedMAX
as 100. So the line
const int MAX = 100;
将转换为
will be converted to
const int 100 = 100;
这是一个无效的语句并导致看到错误消息。
解决方案:
删除行或定义 MAX
的行。
which is an invalid statement and results in the seen error message.
Solution:
Remove that line or the line defining MAX
.
这篇关于[错误]期望在数字常量之前的nonqualified-id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!