【转载】C++中结构体的声明和定义
http://blog.csdn.net/whuslei/article/details/5665289
1 | //定义一个结构体,类型为struct Student |
2 | struct Student |
3 | { |
4 | string name; |
5 | double eng; |
6 | double ch; |
7 | }; |
8 | |
9 | //定义了一个结构体,类型为struct Student;且定义了一个结构体实例,名叫Stu |
10 | struct Student |
11 | { |
12 | string name; |
13 | double eng; |
14 | double ch; |
15 | }Stu; |
16 | |
17 | //定义了无名的结构体,且定义了一个结构体实例,名叫Stu |
18 | struct |
19 | { |
20 | string name; |
21 | double eng; |
22 | double ch; |
23 | }Stu; |
24 | |
25 | //重定义结构体,类型为struct Student 或者是Stu |
26 | typedef struct Student |
27 | { |
28 | string name; |
29 | double eng; |
30 | double ch; |
31 | }Stu; |
32 | |
33 | //重定义结构体,类型为Stu |
34 | typedef struct |
35 | { |
36 | string name; |
37 | double eng; |
38 | double ch; |
39 | }Stu; |
40 |
如果用typedef则,Stu stu;
否则,struct Student stu;