struct _x1 { ...}x1; 和 typedef struct _x2{ ...} x2; 有什么不同?
前者是定义了类_x1和_x1的对象实例x1, 后者是定义了类_x2和_x2的类别名x2 ,
定义结构变量的一般格式为:
struct 结构名
{
类型 变量名;
类型 变量名;
...
} 结构变量;
结构名是结构的标识符不是变量名。
typedef struct 结构名
{
类型 变量名;
类型 变量名;
...
} 结构别名;
typedef struct _point{
int x;
int y;
}point; //定义类,给类一个别名
对应:
point pt1;
pt1.x = 2;
pt1.y = 5;
而
struct _hello{
int x,y;
} hello; //同时定义类和对象
对应:
hello.x = 8;
hello.y = 10;
对C语言又有点了解了。哈哈