首页 / 操作系统 / Linux / C++中结构体的声明和定义的用法
C++中结构体的声明和定义的用法: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;C++ Primer Plus 第6版 中文版 清晰有书签PDF+源代码 http://www.linuxidc.com/Linux/2014-05/101227.htm读C++ Primer 之构造函数陷阱 http://www.linuxidc.com/Linux/2011-08/40176.htm读C++ Primer 之智能指针 http://www.linuxidc.com/Linux/2011-08/40177.htm读C++ Primer 之句柄类 http://www.linuxidc.com/Linux/2011-08/40175.htmC++11 获取系统时间库函数 time since epoch http://www.linuxidc.com/Linux/2014-03/97446.htmC++11中正则表达式测试 http://www.linuxidc.com/Linux/2012-08/69086.htm本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-05/101570.htm