gpt4 book ai didi

c++ - #define 的 "Declaration does not declare anything"错误

转载 作者:行者123 更新时间:2023-12-02 11:11:46 32 4
gpt4 key购买 nike

关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。












想改进这个问题?将问题更新为 on-topic对于堆栈溢出。

2年前关闭。




Improve this question




我试图定义 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;

希望现在你能明白为什么你的编译器讨厌它。

顺便说一句,我意识到您正在做“竞争性编程 [原文如此]”,并且在该领域使所有内容变得简短且不可读是很时髦的,但是如果您想编写任何接近体面的代码,则确实应该避免使用此类宏.同样, do not include implementation headers .

关于c++ - #define 的 "Declaration does not declare anything"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57115804/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com