struct(在C与C++中的区别)
来源:互联网 发布:淘宝卖家订单能删除吗 编辑:程序博客网 时间:2024/05/19 00:16
首先我承认没有系统地学习过C++,今天看到L的代码,我惊了下,struct怎么搞得跟class有点相似,还有构造函数啊~
查了下资料:http://msdn.microsoft.com/en-us/library/64973255(v=VS.90).aspx
struct关键字定义一个结构体类型或一个结构体类型的变量
具体内容点上面连接吧,我就写几点
- 在C++里,结构体(a structure)相同于类(a class),除了它的成员(members)被默认为公有的(public)
- 在C里,必须明确地用struct关键字声明一个结构体(structure);在C++中,一旦类型被定义了就不必要在这样做了
- 当结构体类型被定义后,你可以在闭花括号(the closing brace)和分号之间放置一个或多个以逗号分割的变量名来声明变量
- 结构体变量可以被初始化。但是要在花括号之内完成。(The initialization for each variable must be enclosed in braces)
样例:
// struct1.cpp
struct
PERSON {
// Declare PERSON struct type
int
age;
// Declare member types
long
ss;
float
weight;
char
name[25];
} family_member;
// Define object of type PERSON
int
main() {
struct
PERSON sister;
// C style structure declaration
PERSON brother;
// C++ style structure declaration
sister.age = 13;
// assign values to members
brother.age = 7;
}
struct
POINT {
// Declare POINT structure
int
x;
// Define members x and y
int
y;
} spot = { 20, 40 };
// Variable spot has
// values x = 20, y = 40
struct
POINT there;
// Variable there has POINT type
struct
CELL {
// Declare CELL bit field
unsigned
short
character : 8;
// 00000000 ????????
unsigned
short
foreground : 3;
// 00000??? 00000000
unsigned
short
intensity : 1;
// 0000?000 00000000
unsigned
short
background : 3;
// 0???0000 00000000
unsigned
short
blink : 1;
// ?0000000 00000000
} screen[25][80];
// Array of bit fields
/**************************************************************************
原文来自博客园——Submarinex的博客: www.cnblogs.com/submarine/
*************************************************************************/
分类: C/C++
0 0
- struct(在C与C++中的区别)
- struct 与 union 在C与C++中的区别
- struct 定义在C++与C中的区别
- struct 在C++和C中的区别
- struct在C和C++中的区别
- struct和typedef struct,在C和C++中的区别
- struct和typedef struct在c++和c中的区别
- typedef struct与struct的区别(C语言中的)
- C中的struct与C++中的struct区别以及C++中的struct与C++中的class的区别
- c中的struct与c++中的class的区别
- 【转】typedef struct 用法详解及其在c与c++中的区别
- typedef struct在C语言中的用法那点区别
- Struct结构在C和C++中的区别
- struct结构体在c和c++中的区别
- struct结构在C和C++中的区别
- C与C++ struct区别
- C中的struct与union
- C与C++中的struct
- ucosII信号量---实现较快数据采集与较慢数据处理的同步
- Mybatis3入门之注解方式
- 链表增删节点
- 阿里巴巴面试题汇总
- 关于把图片内容绘制到view中
- struct(在C与C++中的区别)
- 黑马程序员 —— 面向对象(第六天)
- Unit6--problem4--多文件组织多个类的程序
- 进制存储和运算(1)——有符数与无符数
- 第六周项目3用多文件组织多个类的程序
- SGU 194 无源无汇上下界网络流
- c++类的构造函数详解
- Spring transaction 事务 --Isolation & Progation
- syslogd架构