2

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?

JoshDM
  • 4,939
  • 7
  • 43
  • 72
Asmodiel
  • 1,002
  • 1
  • 12
  • 21

2 Answers2

2

% 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

Community
  • 1
  • 1
makc
  • 2,569
  • 1
  • 18
  • 28
1

It is quite impossible for a T% to be null.

Sebastian Redl
  • 69,373
  • 8
  • 123
  • 157
  • Yup, see also: http://msdn.microsoft.com/en-us/library/8903062a%28VS.80%29.aspx, specifically "A tracking reference cannot be assigned null." – Nate Kohl Jul 09 '13 at 13:46