g ++给出错误:'node * link'重新声明为不同类型的符号

时间:2018-04-24 02:46:13

标签: c++ g++

此代码在我的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端出现编译错误?

感谢。

1 个答案:

答案 0 :(得分:2)

  

它可能是在Windows上编译和运行的原因   但是在Linux方面会出现编译错误吗?

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

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

在Windows上,link()不存在。

如果您希望在两个平台上编译代码,请为node*变量使用其他名称。