1
我有一個樹結構,我想找到所有符合給定條件的節點。每次我調用find函數時,它都會返回下一個匹配節點。兒童通過遞歸函數調用進行搜索。比較指針在VC++中神祕失敗
由於某種原因,指針的關鍵比較在此實現中失敗。請參閱下面的代碼,我已經指出了失敗的比較。
HtmlTag* HtmlContent::FindTag(string tagName, string tagParameterContent)
{
if (tagName.empty() && tagParameterContent.empty())
return NULL;
if (this->startTag == NULL)
return NULL;
this->findContinue = this->FindChildren(this->startTag, &tagName, &tagParameterContent);
return this->findContinue;
}
HtmlTag* HtmlContent::FindChildren(HtmlTag* firstTag, string* tagName, string* tagParameterContent)
{
HtmlTag* currentTag = firstTag;
HtmlTag* childrenFound = NULL;
while (currentTag != NULL)
{
if (!tagName->empty() && *tagName == currentTag->tagName)
{
if (tagParameterContent->empty() || currentTag->tagParameters.find(*tagParameterContent, 0) != -1)
{
if (this->findContinue == NULL)
break; // break now when found
else if (this->findContinue == currentTag) // TODO why this fails?
this->findContinue == NULL; // break on next find
}
}
if (currentTag->pFirstChild != NULL)
{
childrenFound = this->FindChildren(currentTag->pFirstChild, tagName, tagParameterContent);
if (childrenFound != NULL)
{
currentTag = childrenFound;
break;
}
}
currentTag = currentTag->pNextSibling;
}
return currentTag;
}
VC++編譯器接受這段代碼,但由於某種原因,我不能在這個比較上放置一個斷點。我想這是優化出來的,但爲什麼?爲什麼這個比較失敗?
這是代碼審查的工作原理,謝謝:) – kaupov 2010-08-27 17:54:16