我的代码有问题。当我运行代码时,短“操作码”的值是错误的52496。所以我逐步调试代码......当我这样做时,“操作码”的值是正确的 4624!有人可以给我一个提示吗?
void packet_get()
{
boost::shared_ptr<boost::array<unsigned char, 2>> opc(new boost::array<unsigned char, 2>);
recv_two_bytes(opc);
unsigned short opcode;
unsigned char * test[2];
test[0] = &opc->at(0); // *test[0] == 0x12
test[1] = &opc->at(1); // *test[1] == 0x10
opcode = 0;
int i = 0;
for(i = 0; i <= 1; i++)
{
opcode = (opcode<<8) | *(test[i]);
}
// opcode should now be short 4624
}