VC中枚举类型这样用为何不行?

来源:百度知道 编辑:UC知道 时间:2024/05/30 22:45:02
enum ERRCODE{ERR01=1,ERR02,ERR03,ERR04,ERR05,ERR06,ERR07,ERR08,ERR09,ERR10,ERR11,ERR12,ERR13,ERR14,ERR15};
switch(ERRCODE)
{
case 1:
m_strEditReceiveMsg="未知指令";
break;
case 2:
m_strEditReceiveMsg="数据无效";
break;
case 3:
m_strEditReceiveMsg="指令功能禁止";
break;
case 4:
m_strEditReceiveMsg="系统被急停";
break;
case 5:
m_strEditReceiveMsg="碰软限位停止";
break;
case 6:
m_strEditReceiveMsg="到X轴负硬限位停止";
break;
case 7:
m_strEditReceiveMsg="到X轴正硬限位停止";
break;
case 8:
m_strEditReceiveMsg="到X轴零位停止";
break;
case 9:
m_strEditReceiveMsg="到Y轴负硬限位停止";
break;
case 10:
m_strEditReceiveMsg="到Y轴正硬限位停止";
break;
case 11:
m_strEditReceiveMsg="到Y轴零位停止";

ERRCODE 现在就像int差不多,switch(int)肯定是不行的了,你得定义一个ERRCODE类型的变量才行

ERRCODE abc;
switch(abc)
{
case 1:
m_strEditReceiveMsg="未知指令";
break;
case 2:
m_strEditReceiveMsg="数据无效";
break;
case 3:
m_strEditReceiveMsg="指令功能禁止";
break;
case 4:
m_strEditReceiveMsg="系统被急停";
break;
case 5:
m_strEditReceiveMsg="碰软限位停止";
break;
case 6:
m_strEditReceiveMsg="到X轴负硬限位停止";
break;
case 7:
m_strEditReceiveMsg="到X轴正硬限位停止";
break;
case 8:
m_strEditReceiveMsg="到X轴零位停止";
break;
case 9:
m_strEditReceiveMsg="到Y轴负硬限位停止";
break;
case 10:
m_strEditReceiveMsg="到Y轴正硬限位停止";
break;
case 11:
m_strEditReceiveMsg="到Y轴零位停止";
break;
case 12: