问题
I'd like to know how in C++/CLI it is possible to check whether an ArrayList is existent.
System::Collections::ArrayList %queue_tx
I tried if ( nullptr != queue_tx ) { queue_tx.Add(msg); }
but that didn't work. I'm passing queue_tx
as a parameter to a function and there's supposed to be the possibility of this parameter not being set (or being set to nullptr
).
The compiler throws '!=' : no conversion from 'System::Collections::ArrayList' to 'nullptr'
.
How do I do this?
回答1:
%
defines a reference variable this is why it cannot be null
if you would have declared the ArrayList like this:
System::Collections::ArrayList^ queue_tx
then your nullptr check would be possible and have a meaning
otherwise just use the queue_tx.Count()
to check if the collection is empty
I would recommend going over:
the difference between reference and pointer variables
When to use a Reference VS Pointers
回答2:
It is quite impossible for a T%
to be null.
来源:https://stackoverflow.com/questions/17549506/how-do-i-check-if-systemcollectionsarraylist-is-empty-nullptr-null