title: How to test gcroot reference for NULL or nullptr?
body: <p>In a C++/CLI project I have a method in a native C++ class where I would like to check a <code>gcroot</code> reference for <code>NULL</code> or <code>nullptr</code>. How do I do this? None of the following seems to work:</p>
  
  <pre><code>void Foo::doIt(gcroot&lt;System::String^&gt; aString)
  {
      // This seems straightforward, but does not work
      if (aString == nullptr)
      {
          // compiler error C2088: '==': illegal for struct
      }
  
      // Worth a try, but does not work either
      if (aString == NULL)
      {
          // compiler error C2678: binary '==' : no operator found
          // which takes a left-hand operand of type 'gcroot&lt;T&gt;'
          // (or there is no acceptable conversion)
      }
  
  
      // Desperate, but same result as above
      if (aString == gcroot&lt;System::String^&gt;(nullptr))
      {
          // compiler error C2678: binary '==' : no operator found
          // which takes a left-hand operand of type 'gcroot&lt;T&gt;'
          // (or there is no acceptable conversion)
      }
  }
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT</strong></p>
  
  <p>The above is just a simplified example. I am actually working on a wrapper library that "translates" between managed and native code. The class I am working on is a native C++ class that wraps a managed object. In the constructor of the native C++ class I get a <code>gcroot</code> reference which I want to check for null.</p>