2010-10-16 57 views
0

我做以下,並獲得該調試錯誤:爲什麼我得到矢量迭代器不兼容?

AguiWidgetBase* AguiWidgetContainer::recursiveGetWidgetUnderMouse(
    AguiWidgetBase* root, const AguiMouseEventArgs &mouse) 
{ 

    AguiWidgetBase* currentNode = root; 
    bool foundsomething = true; 

    while(foundsomething) 
    { 
     foundsomething = false; 
     if(currentNode->getChildCntrolCount() > 0) 
      for (std::vector<AguiWidgetBase*>::const_reverse_iterator rit = 
        currentNode->getChildRBeginIterator(); 
       rit < currentNode->getChildREndIterator(); ++rit) 
      { 
       if(!foundsomething) 
        if ((*rit)->intersectionWithPoint(mouse.getPosition())) 
        { 
         foundsomething = true; 
         currentNode = *rit; 
        } 

       } 
      } 
      return currentNode; 
     } 

    // ... 

它currentNode成爲一個指向根的一個孩子後,並在爲崩潰失敗。

我在做什麼錯?

謝謝

回答

1

您正在重新分配您的迭代器正在檢查的結束位置。

2評論:

  1. 把括號你if語句。你可以不這樣做,但是如果你這樣做並且提醒你縮進,它會使代碼更具可讀性。

  2. 向內部添加一個break語句if以便您不需要繼續遍歷該向量。如果沒有額外的變量和變量檢查,這將完成你想要的。

+0

我該如何解決這個問題? – jmasterx 2010-10-16 02:20:28

+0

@Milo - 看我的編輯。在內部if語句中添加一個break語句,以便短路for循環。但是,不要重新指定迭代器開始。如果你覺得你必須使用不同的變量! – wheaties 2010-10-16 02:21:33

相關問題