typedef struct 和struct
在C和C++中用法有所不同:
(1)C中:
typedef struct Student { int a; }Stu;
定义变量的时候就可以使用Stu student1;此时Stu=struct student.
struct Student { int a; }student1;
如果没有则定义的时候必须 struct Student student2,student3;
(2)C++中
typedef struct的用法是相同的;
但对于stuct
struct Student { int a; };
在定义变量的时候可以直接是Student s1;而不必在Student之前加struct。
(3)另类用法
在C语言中:
typedef struct { int num; int age; }aaa,bbb,ccc;
这算什么呢?这相当于
typedef struct { int num; int age; }aaa; typedef aaa bbb; typedef aaa ccc;
也就是说aaa==bbb==ccc,他们都是结构体类型。
.......
参考:http://www.cnblogs.com/qyaizs/articles/2039101.html
浙公网安备 33010602011771号