Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 如何:检查数组是否<;T>;^==空PTR?C++;/CLI_.net_Generics_C++ Cli_Command Line Interface - Fatal编程技术网

.net 如何:检查数组是否<;T>;^==空PTR?C++;/CLI

.net 如何:检查数组是否<;T>;^==空PTR?C++;/CLI,.net,generics,c++-cli,command-line-interface,.net,Generics,C++ Cli,Command Line Interface,我使用泛型在C++/CLI中完成了一个非常基本的类。 如何检查泛型数组^是否等于nullptr generic<class T> where T: IGenericContainable public ref class FIBEXGenericContainer abstract : AbstractFIBEXNode { public: property array<T>^ Children; public: property T default[

我使用泛型在C++/CLI中完成了一个非常基本的类。 如何检查泛型数组^是否等于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();
        }
    }
};
通用,其中T:IGenericContainable
公共引用类FIBEXGenericContainer摘要:AbstractFIBEXNode
{
公众:
属性数组^Children;
公众:
属性T默认值[字符串^]
{
无法获取(字符串^aID)
{
if(nullptr==子级)
控制台::WriteLine(“这不会发生,因为我在上面的一行中得到一个NullReferenceException”);
每个(儿童的T tObj)
{
如果(aID==tObj->ID)
返回tObj;
}
返回T();
}
}
};

谢谢你们

听起来像是
为空,而不是
此->子项
。有时可以对空引用调用非虚函数,结果是您看到的(失败发生在函数内部,而不是调用方)。

Hi Ben,谢谢您的建议。我自己永远也不会明白这一点。现在我用谷歌快速浏览了一下,我就聪明多了