你好,游客 登录 注册 搜索
背景:
阅读新闻

C++中结构体的声明和定义的用法

[日期:2014-05-11] 来源:Linux社区  作者:xf_pku [字体:大 中 小]

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.htm

C++11 获取系统时间库函数 time since epoch http://www.linuxidc.com/Linux/2014-03/97446.htm

C++11中正则表达式测试 http://www.linuxidc.com/Linux/2012-08/69086.htm

本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-05/101570.htm

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款