define & typedef 的识别
作者:
飞雨2013 | 来源:发表于
2016-12-17 11:03 被阅读31次
define : 文本替换
typedef : 为类型取别名
define : 预处理命令,在编译前运行。
typedef : 编译期运行(正是因为其在编译期执行,所以有类型检查的能力)
define : 无作用域限制(只要是在前面定义过的预处理宏,在之后都能使用)
typedef : 有作用域限制
---------------------------------------------------------------
void func1()
{
#define HW "HelloWorld";
}
void func2()
{
string str = HW;
cout << str << endl;
}
---------------------------------------------------------------
void func1()
{
typedef unsigned int UINT;
}
void func2()
{
UINT uValue = 5;//error C2065: 'UINT' : undeclared identifier
}
---------------------------------------------------------------
本文标题:define & typedef 的识别
本文链接:https://www.haomeiwen.com/subject/lzpomttx.html
网友评论