相关疑难解决方法(0)

c ++变量的多个定义

我有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'的多重定义"并且我不知道为什么,它似乎应该可以正常工作.

c++ compiler-errors

19
推荐指数
2
解决办法
2万
查看次数

标签 统计

c++ ×1

compiler-errors ×1