The initialization operation is skipped by the case label.

Source: Internet
Author: User

 

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;
}
}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.