Papers/programming
declare an object in switch logic
tomato13
2013. 11. 21. 22:47
void tc4()
{
switch(1){
case 1:
CChild* pObj = new CChild();
break;
case 2:
break;
}
}
Do you think the upper code is compiled well?
When I tried, the compiler showed a message below.
( I used visual studio 2010)
1>.\main.cpp(38) : error C2360: initialization of 'pObj' is skipped by 'case' label
When I changed the code like below,
void tc4()
{
switch(1){
case 1:
{
CChild* pObj = new CChild();
}
break;
case 2:
break;
}
}
It has been compiled well.