pointers - 如何检查 System::Collections:ArrayList 是否为空/nullptr/null?

标签 pointers reference c++-cli

我想知道如何在 C++/CLI 中检查 ArrayList 是否存在。

System::Collections::ArrayList %queue_tx

我试过if ( nullptr != queue_tx ) { queue_tx.Add(msg); }但这没有用。我路过queue_tx作为函数的参数,并且应该有可能未设置此参数(或设置为 nullptr )。

编译器抛出 '!=' : no conversion from 'System::Collections::ArrayList' to 'nullptr' .

我该怎么做?

最佳答案

% 定义了一个引用变量,这就是为什么它不能为 null

如果您像这样声明 ArrayList:

System::Collections::ArrayList^ queue_tx

那么你的 nullptr 检查将是可能的并且有意义

否则只需使用queue_tx.Count()来检查集合是否为空

我建议查看:

the difference between reference and pointer variables

When to use a Reference VS Pointers

关于pointers - 如何检查 System::Collections:ArrayList 是否为空/nullptr/null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17549506/

相关文章:

c++ - 在 C++ 中引用 Sub Array 2D

wpf - MC3074 - "clr-namespace..."中不存在类型

c++ - 在构造函数中分配双向链表指针

c - char指针的伪变量数组(字符串数组)在输入后崩溃?

Java OpenGL(JOGL) 对象数组和 FloatBuffer

c - 是否有一种故障安全方法来确定 C 中指针的对齐/尾随位?

c++ - 返回对本地对象的引用时的编译器警告

c++-cli - 为什么不能将跟踪引用用作类成员?

.net - C++中的 “^”符号是什么?

c# - 如何从 C++ COM 迁移到 C++CLI