views:

41

answers:

1

Hi all,

I've done a pretty basic class in C++/CLI using generics. How can I check if the generic array^ equals nullptr?

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();
        }
    }
};

Thank you guys!

+2  A: 

Sounds like this is null, not this->Children. A non-virtual function can sometimes be called on a null reference, with the results you see (failure occurs inside the function instead of in the caller).

Ben Voigt
Hi Ben, thank you for that great piece of advice. I'd have never figured that out for myself. Now that I did a quick look around with google I'm much wiser
yas4891