typeof与typedef的区别:
typedef用来定义类型别名,c/c++里都有,属于语言的一个特性,和mfc无关
比如
typedef int* intptr;
intptr a; // 相当于int* a;
typeof,我所知道的是gcc中对c/c++语法的一个扩展,用来静态获取参数类型
比如
int a = 3;
typeof(a) b = 4; // 相当于 int b = 4;
typeof("12345") c = "abcde"; // 相当于 const char c[6] = "abcde"
vector<typeof(1.234)> a; // 相当于 vector<double> a;
typeof构造的主要应用是用在宏定义中。可以使用typeof关键字来引用宏参数的类型。
因此,在没有将类型名明确指定为宏实参的情况下,构造带有所需类型的对象是可能的。
例如:
#define swap(x, y) {typeof(x) tmp = x; x = y; y = tmp;}