2010-08-02 39 views
0

我使用泛型在C++/CLI中完成了一個非常基礎的類。 如何檢查通用數組是否等於nullptr?如何:檢查數組<T>^== nullptr? C++/CLI

generic<class T> where T: IGenericContainable 
public ref class FIBEXGenericContainer abstract : AbstractFIBEXNode 
{ 
public: 
    property array<T>^ Children; 

public: 

    property T default[String^] 
    { 
     T get(String^ aID) 
     { 
      if(nullptr == Children) 
       Console::WriteLine("this won't happen, because I get an NullReferenceException in the above line"); 

      for each(T tObj in Children) 
      { 
       if(aID == tObj->ID) 
        return tObj; 
      } 

      return T(); 
     } 
    } 
}; 

謝謝各位!

回答

2

聽起來像this爲空,而不是this->Children。有時可以在空引用上調用非虛函數,並看到結果(失敗發生在函數內部而不是調用者中)。

+0

嗨,本,謝謝你的一個偉大的意見。我從來沒有想過爲自己。現在我快速瀏覽了一下谷歌,我很聰明 – yas4891 2010-08-02 13:58:05