#define是一种机械的文本替代,typedef(C/C++),using属于(C++),using不仅可以做typedef的事情,还可以做typedef不能做的事情。无论是typedef还是using,都是取一个类型别名。
| 关键字 | 作用域 | 类型别名 | 模板别名 | 类型检查 |
|---|---|---|---|---|
| define | 文件作用域 | 可 | 否 | 否 |
| typedef | 位置决定 | 可 | 否 | 是 |
| using | 位置决定 | 可 | 可 | 可 |
#define知识补充:
- #define定义宏函数会出现的问题:
#define SQUARE(x) x*x
int main()
{
int a = 2;
std::cout
关注
打赏
