gpt4 book ai didi

c++ - g++ 给出错误 : ‘node* link’ redeclared as different kind of symbol

转载 作者:行者123 更新时间:2023-11-30 03:24:05 25 4
gpt4 key购买 nike

此代码在我的 Windows 机器上的 Codelite IDE 中编译和运行良好(使用 g++.exe):

#include <iostream>
#include <cstdlib>
using std::cout;
using std::endl;

struct node {
int i;
node* next;
node(int x, node* t) {
i = x;
next = t;
}
};


node *link;

int main()
{
cout << "Yes!" << endl;
return 0;
}

但同样的代码,在使用 g++ 的 Linux 机器上编译时会出现以下错误。

simpleTest.cpp:16: error: ‘node* link’ redeclared as different kind of symbol
/usr/include/unistd.h:809: error: previous declaration of ‘int link(const char*, const char*)’

可能是什么原因导致它在 Windows 端编译和运行良好,但在 Linux 端出现编译错误?

谢谢。

最佳答案

What could be the reason for it to compile and run fine on Windows side but give compilation errors on Linux side?

在 Linux 上,link()已在 unistd.h 中声明为函数:

int link(const char *path1, const char *path2);

在 Windows 上,link() 不存在。

如果您希望您的代码在两个平台上都可以编译,请为您的 node* 变量使用不同的名称。

关于c++ - g++ 给出错误 : ‘node* link’ redeclared as different kind of symbol,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49992693/

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