奇怪的 C++ 错误,不合格的 ID,重新声明

C. *_*sti 0 c++ file

我想创建一个项目,我有3个文件,一个test.cppsomething.h和一个something.cpp。他们来了:

测试.cpp:

#include <bits/stdc++.h>
#define f cin
#define g cout
#include "something.h"
using namespace std;

int main(void)
{
    int x;
    register(x);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

东西.h:

#ifndef __SOMETHING__H_
#define __SOMETHING__H_
#include <bits/stdc++.h>

void register(int x);
#endif
Run Code Online (Sandbox Code Playgroud)

东西.cpp:

#include "something.h"

void register(int x)
{
    std::cout << x << '\n';
}
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误:

In file included from test.cpp:4:0:
something.h:5:15: error: expected unqualified-id before ‘int’
 void register(int x);
               ^~~
something.h:5:15: error: expected ‘)’ before ‘int’
test.cpp: In function ‘int main()’:
test.cpp:10:15: error: ISO C++ forbids declaration of ‘x’ with no type [-fpermissive]
     register(x);
               ^
test.cpp:10:15: error: redeclaration of ‘int x’
test.cpp:9:9: note: ‘int x’ previously declared here
     int x;
         ^
In file included from something.cpp:1:0:
something.h:5:15: error: expected unqualified-id before ‘int’
 void register(int x);
               ^~~
something.h:5:15: error: expected ‘)’ before ‘int’
something.cpp:3:15: error: expected unqualified-id before ‘int’
 void register(int x)
               ^~~
something.cpp:3:15: error: expected ‘)’ before ‘int’
Run Code Online (Sandbox Code Playgroud)

为什么它告诉我我重新定义了 x?当我只想用它的值调用 register 时。

Mik*_*CAT 5

register是C++ 中的保留字。因此,您必须给出另一个(无保留的)名称。

更多信息:C++ 中的注册关键字_C++_帮酷编程问答