注册 登录
编程论坛 C++教室

数组问题了 相加不了

linkang1024 发布于 2013-09-08 14:23, 596 次点击
unsigned char Cmd[]= {0x40, 0x40, 0x00, 0x00, 0x0b, 0x01};



为什么里面的值相加不了? Cmd[0]+Cmd[1]...就会提示 subscript requires array or pointer type

为啥啊 不懂
4 回复
#2
peach54602013-09-08 14:39
怎么可能加不了
贴代码...
不贴代码我怎么跟你看...
会不会问问题啊
#3
linkang10242013-09-08 14:45
回复 2楼 peach5460
unsigned char Cmd[]= {0x40, 0x40, 0x00, 0x00, 0x0b, 0x01,
                     0x04,                            //0x03 相对位移 0x04绝对位移
                     0,                                //10,20,30,40,50,60 轴号
                     0, 0,                            //加速度
                     0, 0, 0, 0,                    //速度
                     0, 0, 0, 0,                    //位移
                     0,                                //标志位
                     0x23, 0x23};   



unsigned char AddSum, SpeedSum, ShiftSum, CmdSum;
CmdSum = 0;   

    for(k=4;k<7;k++)
    {
        CmdSum +=Cmd[k];  
    }

E:\vcProgram\AllLed\AllLedDlg.cpp(732) : error C2109: subscript requires array or pointer type
E:\vcProgram\AllLed\AllLedDlg.cpp(732) : error C2297: '+=' : illegal, right operand has type 'void (__thiscall CAllLedDlg::*)(unsigned char *)'   

错误指向      CmdSum +=Cmd[k]; 这一句。
#4
情.难言ゝ2013-09-08 18:16
下标需要数组或指针类型
#5
qiqid2013-09-13 10:51
我用VC++6.0编译器通过了这个程序,输出16,按照16进制转化为10进制答案没错。
1