我正在使用Qt Creator开发C ++应用程序,并使用调试器来检查代码,我试图了解调试器报告的一些非常奇怪的结果。
if ( intDelimiter == -1
&& (intOpB = strProcessed.indexOf("[")) >= 0
&& (intClB = strProcessed.indexOf("]", ++intOpB) >= 0) ) {
strRef = strProcessed.mid(intOpB, intClB - intOpB);
if ( pobjNode != NULL ) {
strProcessed.replace(strRef, pobjNode->strGetAttr(strRef));
}
我在线路上有一个断点:
strRef = strProcessed.mid(intOpB, intClB - intOpB);
在上面的代码片段中,strProcessed包含:
"1079-[height]"
达到断点时,intClB包含1,而intOpB包含6。
intOpB是正确的,因为从indexOf返回的值是5,然后在搜索“]”之前将其递增,但是intClB是不正确的,为什么调试器将其报告为1?这对我来说毫无意义。
我在用:
Qt Creator 3.6.0
Based on Qt 5.5.1 (GCC 4.9.1 20140922 (Red Hat 4.9.1-10), 64bit)
Built On Dec 15 2015 01:01:12
Revision: b52c2f91f5
正如king_nak所发现的,更正后的代码应为:
if ( intDelimiter == -1
&& ((intOpB = strProcessed.indexOf("[")) >= 0
&& (intClB = strProcessed.indexOf("]", ++intOpB)) >= 0) ) {
strRef = strProcessed.mid(intOpB, intClB - intOpB);
if ( pobjNode != NULL ) {
strProcessed.replace(strRef, pobjNode->strGetAttr(strRef));
}
}
您放错了括号:
(intClB = strProcessed.indexOf("]", ++intOpB) >= 0)
这会将strProcessed.indexOf("]", ++intOpB) >= 0
to的结果分配intClB
为int
。就像这样的说法true
,intClB = 1
。
你要:
(intClB = strProcessed.indexOf("]", ++intOpB) ) >= 0
^ Brace here
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句