#define 的"Declaration does not declare anything"错误
"Declaration does not declare anything" error for #define
我试图将ll
定义为long long
的别名。但是,这没有编译并抛出错误。
我在Windows机器上使用VS Code。我也在使用 gcc 版本 8.2.0。
这是代码 -
#include <bits/stdc++.h>
using namespace std;
#define ll long long int;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin >> t;
return 0;
}
在编译时,我得到了这个错误 -
test.cpp: In function 'int main()':
test.cpp:5:22: error: declaration does not declare anything [-fpermissive]
#define ll long long int;
^~~
test.cpp:12:5: note: in expansion of macro 'll'
ll t;
^~
test.cpp:12:8: error: 't' was not declared in this scope
ll t;
^
test.cpp:12:8: note: suggested alternative: 'tm'
ll t;
奇怪的是,这个确切的代码在其他机器上工作。有人可以向我解释一下吗?
预处理器指令后没有分号。
所以这个:
#define ll long long int;
意味着ll
字面上是long long int;
.
然后您的声明:
ll t;
真的是:
long long int; t;
这与
:long long int;
t;
希望现在你能明白为什么你的编译器讨厌它。
顺便说一句,我意识到你正在做"竞争性编程[原文如此]",并且在这个领域让一切都简短和不可读是时髦的,但如果你想写任何接近体面的代码,真的要避免像这样的宏。同样,不要包含实现标头。
相关文章:
- 表示"accepting anything for this template argument" C++概念的通配符
- 编译器是否实际使用我的"omp declare simd"函数?
- #define 的"Declaration does not declare anything"错误
- 你如何在C++"Press ENTER to continue, anything else to quit"
- Declare a cv::Mat of NaN
- 函数上漆"was not declare in this scope"
- 提升精神:如何将"anything from line till particular word"收集到一个变量中?
- 接受C++"anything"的模板
- 如何"declare"全局结构?
- C++ - "Cannot declare parameter 'anonymous' to be of abstract type"
- Do Default Destructors Do Anything?
- "declaration does not declare anything"错误的原因是什么?
- "Declaration does not declare anything"和"expected unqualified-id"
- "You can't forward declare classes that overload operator&" ?