结构体变量中成员的初始化解决方法
结构体变量中成员的初始化
enum PTYPE{
P_PROBABILIBY = 0x01,
P_ATTACK = 0x02,
P_MERGER = 0x03
};
enum KEY{
K_PROBABILIBY = 0x01,
K_ATTACK = 0x02,
K_MERGER = 0x03,
K_PROBCFG = 0x04,
K_ATTACKCFG = 0x05
};
struct MyProtocol{
unsigned char begin;
//unsigned char type;
PTYPE type;
KEY key;
// unsigned char key;
unsigned short reserve;
unsigned char end;
}Data;
Data.begin = BEGIN;
Data.end = END;
Data.reserve = 0;
我想把结构体的一个对象的某些成员初始化:
Data.begin = BEGIN;
Data.end = END;
Data.reserve = 0;
为什么老是出错呢?谢谢各位
------解决方案--------------------
没定义你枚举类型
------解决方案--------------------
struct MyProtocol{
unsigned char begin;
//unsigned char type;
PTYPE type;
KEY key;
// unsigned char key;
unsigned short reserve;
unsigned char end;
}Data;
前面加一个typedef???
试试看。。。
enum PTYPE{
P_PROBABILIBY = 0x01,
P_ATTACK = 0x02,
P_MERGER = 0x03
};
enum KEY{
K_PROBABILIBY = 0x01,
K_ATTACK = 0x02,
K_MERGER = 0x03,
K_PROBCFG = 0x04,
K_ATTACKCFG = 0x05
};
struct MyProtocol{
unsigned char begin;
//unsigned char type;
PTYPE type;
KEY key;
// unsigned char key;
unsigned short reserve;
unsigned char end;
}Data;
Data.begin = BEGIN;
Data.end = END;
Data.reserve = 0;
我想把结构体的一个对象的某些成员初始化:
Data.begin = BEGIN;
Data.end = END;
Data.reserve = 0;
为什么老是出错呢?谢谢各位
------解决方案--------------------
没定义你枚举类型
------解决方案--------------------
struct MyProtocol{
unsigned char begin;
//unsigned char type;
PTYPE type;
KEY key;
// unsigned char key;
unsigned short reserve;
unsigned char end;
}Data;
前面加一个typedef???
试试看。。。