複 合 型 別
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);