复合类型
C/C++
编辑struct
struct
,
struct
class
class
struct
则是
class
struct
类型。对于struct
struct
struct
也是struct
,并有
struct
struct
对象
struct Account {
int account_number;
char *first_name;
char *last_name;
float balance;
};
struct Account
struct Account myAccount;
,它有myAccount.account_number
访问myAccount.balance
访问first_name
last_name
组件。myAccount
struct account
typedef
语句并不罕见,其为 struct
typedef struct Account_ {
int account_number;
char *first_name;
char *last_name;
float balance;
} Account;
typedef
,struct
struct Account
Account
。
其它
struct Vector {
float x;
float y;
float z;
};
Vector
复合类型为类velocity
,Vector velocity;
,velocity
velocity.x = 5;
,velocity
x
struct Color {
int red;
int green;
int blue;
};
Vector
Color
复合类型Vertex
复合类型:
struct Vertex {
Vector position;
Color color;
};
以同样的Vertex
类型Vertex v;
,并以如下v
:
v.position.x = 0.0;
v.position.y = 1.5;
v.position.z = 0.0;
v.color.red = 128;
v.color.green = 0;
v.color.blue = 255;
原始 子 类型检查
编辑
刚开struct
,
struct ifoo_old_stub {
long x, y;
};
struct ifoo_version_42 {
long x, y, z;
char *name;
long a, b, c;
};
void operate_on_ifoo(struct ifoo_old_stub *);
struct ifoo_version_42 s;
. . .
operate_on_ifoo(&s);