Export (0) Print
Expand All

auto_gcroot::operator! 

Operator for using auto_gcroot in a conditional expression.


bool operator!() const;

true if the wrapped object is invalid; false otherwise.

// msl_auto_gcroot_operator_not.cpp
// compile with: /clr
#include <msclr\auto_gcroot.h>

using namespace System;
using namespace msclr;

int main() {
   auto_gcroot<String^> s;
   if ( s ) Console::WriteLine( "s is valid" );
   if ( !s ) Console::WriteLine( "s is invalid" );
   s = "something";
   if ( s ) Console::WriteLine( "now s is valid" );
   if ( !s ) Console::WriteLine( "now s is invalid" );
   s.reset();
   if ( s ) Console::WriteLine( "now s is valid" );
   if ( !s ) Console::WriteLine( "now s is invalid" );
}

Output

s is invalid
now s is valid
now s is invalid

Header file <msclr\auto_gcroot.h>

Namespace msclr

Community Additions

ADD
Show:
© 2014 Microsoft