有关于重定义~请大家看看
时间:2011-12-27
来源:互联网
我在global.h里面定义全局变量
下面给出接口
#ifndef __global_H
#define __global_H
//---------------------------------------------------include----------------------------------------
#include <windows.h>
//----------------------------------------------------definer------------------------------------
#define GREEN FOREGROUND_GREEN
#define RED FOREGROUND_RED
#define MAX_SIZE 100
HANDLE hOut;// get the handle of the console
WORD OriginalColor;
//----------------------------------------------------Function---------------------------------------------
void setColor(WORD Color);
void colorReset();
int mainTask();
//--------------------------------------------------------------------------------------------------------
#undef __global_H
#endif
然后在一个类里面进行了调用
***********************************************************************************************
#ifndef ...
#define....
#include "global.h"
class arithmetic
{
public:
void show();
.....
....
private:
...
...
};
/
----------------------------
#include "global.h"
#include "arithmetic.h"
void arithmetic::show()
{
setColor(GREEN);
cout<<"test"<<endl;
}
#endif
***********************************************主函数********************************
#include "arithmetic.h"
#include "global.h"
#include <iostream>
using namespace std;
int main(int argc,char* argv[])
{
arithmetic test;
test.print();
return 0;
}
编译错误
main.obj : error LNK2005: "unsigned short OriginalColor" (?OriginalColor@@3GA) already defined in arithmethic.obj
1>main.obj : error LNK2005: "void * hOut" (?hOut@@3PAXA) already defined in arithmethic.obj
不是调用了ifndef吗?为什么还会如此呢?
下面给出接口
#ifndef __global_H
#define __global_H
//---------------------------------------------------include----------------------------------------
#include <windows.h>
//----------------------------------------------------definer------------------------------------
#define GREEN FOREGROUND_GREEN
#define RED FOREGROUND_RED
#define MAX_SIZE 100
HANDLE hOut;// get the handle of the console
WORD OriginalColor;
//----------------------------------------------------Function---------------------------------------------
void setColor(WORD Color);
void colorReset();
int mainTask();
//--------------------------------------------------------------------------------------------------------
#undef __global_H
#endif
然后在一个类里面进行了调用
***********************************************************************************************
#ifndef ...
#define....
#include "global.h"
class arithmetic
{
public:
void show();
.....
....
private:
...
...
};
/
----------------------------
#include "global.h"
#include "arithmetic.h"
void arithmetic::show()
{
setColor(GREEN);
cout<<"test"<<endl;
}
#endif
***********************************************主函数********************************
#include "arithmetic.h"
#include "global.h"
#include <iostream>
using namespace std;
int main(int argc,char* argv[])
{
arithmetic test;
test.print();
return 0;
}
编译错误
main.obj : error LNK2005: "unsigned short OriginalColor" (?OriginalColor@@3GA) already defined in arithmethic.obj
1>main.obj : error LNK2005: "void * hOut" (?hOut@@3PAXA) already defined in arithmethic.obj
不是调用了ifndef吗?为什么还会如此呢?
作者: judymac 发布时间: 2011-12-27
#ifndef __global_H
#define __global_H
...
#undef __global_H
#endif
最后undef干嘛???
#define __global_H
...
#undef __global_H
#endif
最后undef干嘛???
作者: luciferisnotsatan 发布时间: 2011-12-27
#include "global.h"
这个去掉
这个去掉
作者: qscool1987 发布时间: 2011-12-27
引用 2 楼 qscool1987 的回复:
#include "global.h"
这个去掉
#include "global.h"
这个去掉
去掉还怎么调用啊~
我里面还有maxSize在class arithmetic有用到的~
作者: judymac 发布时间: 2011-12-27
引用 1 楼 luciferisnotsatan 的回复:
#ifndef __global_H
#define __global_H
...
#undef __global_H
#endif
最后undef干嘛???
#ifndef __global_H
#define __global_H
...
#undef __global_H
#endif
最后undef干嘛???
undef加上也没什么关系呀~,去掉也是一样的~
作者: judymac 发布时间: 2011-12-27
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28