我想创建一个项目,我有3个文件,一个test.cpp,something.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 时。
| 归档时间: |
|
| 查看次数: |
41 次 |
| 最近记录: |