我有4个文件(2个标题和2个代码文件).FileA.cpp,FileA.h,FileB.cpp,FileB.h
FileA.cpp:
#include "FileA.h"
int main()
{
hello();
return 0;
}
void hello()
{
//code here
}
Run Code Online (Sandbox Code Playgroud)
FileA.h:
#ifndef FILEA_H_
#define FILEA_H_
#include "FileB.h"
void hello();
#endif /* FILEA_H_ */
Run Code Online (Sandbox Code Playgroud)
FileB.cpp:
#include "FileB.h"
void world()
{
//more code;
}
Run Code Online (Sandbox Code Playgroud)
FileB.h:
#ifndef FILEB_H_
#define FILEB_H_
int wat;
void world();
#endif /* FILEB_H_ */
Run Code Online (Sandbox Code Playgroud)
当我尝试编译(使用eclipse)时,我得到了"wat'的多重定义"并且我不知道为什么,它似乎应该可以正常工作.