Today, I encountered a problem when writing a program. The Code is as follows: compile and report an error. D:/demo/VC: the socket simple chat program/testserver/testserverdlg. CPP (245): Error c2360: the initialization operation of "is8001" is skipped by the "case" label.
Switch (imessageid)
{
Case 8001:
Initsystem8001 * is8001 = new initsystem8001;
Ircvd = m_sconnectsocket.receive (is8001, sizeof (initsystem8001 ));
Break;
Case 8003:
Aliverequest8003 * ar8003 = new aliverequest8003;
Ircvd = m_sconnectsocket.receive (ar8003, sizeof (aliverequest8003 ));
Break;
}
After reading the webpage, it means that this case 8001: The statement may not be executed (other cases are executed), leading to variable initialization and subsequent errors, so we need to put the variables in front of the switch to declare initialization, but I don't want to put the initialization in front of the switch. There is also a solution to define the internal variables in swith with parentheses.
Switch (imessageid)
{
Case 8001:
{
Initsystem8001 * is8001 = new initsystem8001;
Ircvd = m_sconnectsocket.receive (is8001, sizeof (initsystem8001 ));
Break;
}
Case 8003:
{
Aliverequest8003 * ar8003 = new aliverequest8003;
Ircvd = m_sconnectsocket.receive (ar8003, sizeof (aliverequest8003 ));
Break;
}
}