大神帮小弟我看看这个代码为啥不对,它老是提醒swap非法,和{没有匹配项【改成正确的代码,多谢】

大神帮我看看这个代码为啥不对,它老是提醒swap非法,和{没有匹配项【改成正确的代码,谢谢】
else if (nSel1==0)
{
CString s = "";
s = m_edit1;
HexToStr((const BYTE *)s.GetBuffer(),s.GetLength(),hex); 
s.Format("%s",hex);
int swap(int in)
{
int out,i=0;
char *p_in=(char*)&in,*p_out=(char*)&out;
while (i<sizeof(int))
p_out[i++]=(p_in[sizeof(int)-1-i]&0x0f)<<4|(p_in[sizeof(int)-1-i]&0xf0)>>4;/*赋值运算先算右面,所以要把i++放在左面*/
return out;
}
mfc

------解决方案--------------------
楼主你好
除非你了解CString是怎样管理内存的,否则不要使用GetBuffer和ReleaseBuffer
除非你了解强制转换是怎样进行的,否则不要使用强制转换
------解决方案--------------------
函数不能嵌套定义,,我想原来格式可能是这样的,楼主发下else if上面的的代码看看。


else if (nSel1==0)
{
CString s = "";
s = m_edit1;
HexToStr((const BYTE *)s.GetBuffer(),s.GetLength(),hex); 
s.Format("%s",hex);
}
}
int swap(int in)
{
int out,i=0;
char *p_in=(char*)&in,*p_out=(char*)&out;
while (i<sizeof(int))
p_out[i++]=(p_in[sizeof(int)-1-i]&0x0f)<<4
------解决方案--------------------
(p_in[sizeof(int)-1-i]&0xf0)>>4;/*赋值运算先算右面,所以要把i++放在左面*/
return out;
}