-
December 28th, 2012, 02:03 AM
#1
strange switch case problem
Code:
template<class T>
T GetValue<T>::get(TiXmlNode* pParent)
{
T attr;
if ( !pParent ) return attr;
TiXmlNode* pChild;
TiXmlText* pText;
int t = pParent->Type();
switch ( t )
{
case TiXmlNode::TINYXML_DOCUMENT:
break;
case TiXmlNode::TINYXML_ELEMENT:
attr =get_attribs(pParent->ToElement());
break;
case TiXmlNode::TINYXML_COMMENT:
break;
case TiXmlNode::TINYXML_UNKNOWN:
break;
case TiXmlNode::TINYXML_TEXT:
pText = pParent->ToText();
break;
case TiXmlNode::TINYXML_DECLARATION:
break;
default:
break;
}
for ( pChild = pParent->FirstChild(); pChild != 0; pChild = pChild->NextSibling())
{
get( pChild );
}
return attr;
}
A breakpoint at
case TiXmlNode::TINYXML_DOCUMENT:
break; // here
is never hit, why? It falls thru to the for loop straight off. The matching value is correct.
Thanks
Jack
Last edited by lucky6969b; December 28th, 2012 at 02:31 AM.
-
December 28th, 2012, 05:15 AM
#2
Re: strange switch case problem
Originally Posted by lucky6969b
is never hit, why? It falls thru to the for loop straight off.
Well, if map and terrain don't match trust the terrain.
-
December 28th, 2012, 10:33 AM
#3
Re: strange switch case problem
Originally Posted by lucky6969b
A breakpoint at
case TiXmlNode::TINYXML_DOCUMENT:
break; // here
is never hit, why? It falls thru to the for loop straight off. The matching value is correct.
The term "fall through" has a very specific meaning in the context of switch statements. You should look it up.
What likely happens, is that the compiler implements the switch statement as a jump table and directly jumps to the next statement based on the value used in the switch. The break is only a control statement and doesn't really do anything, so it is skipped.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|