【发布时间】:2014-06-01 21:38:52
【问题描述】:
我有这两个文件:
Circles.h:
#ifndef CIRCLE_H
#define CIRCLE_H
#include <map>
using namespace std;
map<int, int> colormap;
#endif
main.cpp:
#include <iostream>
#include "Circles.h"
using namespace std;
int main ()
{
int a;
cin>>a;
cout<<a<<endl;
return 0;
}
错误:
||=== 构建:在多游戏中调试(编译器:GNU GCC 编译器)===| obj\Debug\main.o||在函数
ZSt11__addressofISt4pairIKiN2sf5ColorEEEPT_RS5_':| D:\SFML Projects\Mulit-game\main.cpp|7|multiple definition ofcolormap'| obj\Debug\Circles.o:c:\program files (x86)\codeblocks\mingw\lib\gcc\mingw32\4.8.1\include\c++\mingw32\bits\gthr-default.h|300|首先在这里定义| ||=== 构建失败:2 个错误,0 个警告(0 分钟,0 秒)===|
我不知道为什么会这样,因为我搜索了我项目的所有文件,但地图只在 Circles.h 中找到。
【问题讨论】:
-
请发布您的完整代码;
colormap在您发布的内容中不存在。 -
colormap 和 stuff 一样。
-
我不知道这是否会有所不同,但不要在头文件中使用
using namespace。它可能导致各种名称冲突。请改用std::map<int, int> colormap;。 -
我怀疑
Circles.h包含在多个源文件中。有了它,您将获得具有相同 id 的变量的 两个 定义。extern- 在头文件中声明并在 one 源文件中直接定义。 -
不,Fred 仍然是同样的错误,即