struct和typedef struct
来源:互联网 发布:淘宝客服办公室图片 编辑:程序博客网 时间:2024/05/16 05:26
大一的C++基本还回去了。
转载自:http://www.cnblogs.com/qyaizs/articles/2039101.html
首先,在C中定义一个结构体类型要用typedef:
typedef struct Student
{
int a;
}Stu;
于是在声明变量的时候就可:Stu stu1;(如果没有typedef就必须用struct Student stu1;来声明)
这里的Stu实际上就是struct Student的别名。Stu==struct Student
另外这里也可以不写Student(于是也不能struct Student stu1;了,必须是Stu stu1;)
但在c++里很简单,直接
struct Student
{
int a;
};
于是就定义了结构体类型Student,声明变量时直接Student stu2;
其次:
在c++中如果用typedef的话,又会造成区别:
struct Student
{
int a;
}stu1;//stu1是一个变量
typedef struct Student2
{
int a;
}stu2;//stu2是一个结构体类型=struct Student
使用时可以直接访问stu1.a
但是stu2则必须先 stu2 s2;
然后 s2.a=10;
0 0
- struct和typedef struct
- struct和typedef struct
- struct和typedef struct
- struct 和 typedef struct
- struct和typedef struct
- struct和typedef struct
- struct和typedef struct
- struct和typedef struct
- struct和typedef struct
- typedef struct和struct
- struct和typedef struct
- struct和typedef struct
- struct和typedef struct
- struct和typedef struct
- struct和typedef struct
- struct和typedef struct
- struct和typedef struct
- struct和typedef struct
- 将Clob对象转换成String对象
- 对话框中控件的几种访问方法
- 用PHP将Unicode 转化为UTF-8
- HDU 2094 产生冠军
- 第二章第十八题
- struct和typedef struct
- CSS中的display属性
- post上传
- WaitForSingleObject
- 关于TNS_ADMIN环境变量
- IO流-操作与规律
- 计算机的潜意识--从机器学习谈起
- 动态获取系统当前时间
- starting Tomcat v7.0 Server at localhost has encountered a problem