auto_gcroot::operator bool

条件式で auto_gcroot を使用する演算子。

operator bool() const;

戻り値

ラップされたオブジェクトが有効な場合true ; 別の方法で false 。

解説

整数型に変換できないため bool より安全であるこの演算子は _detail_class::_safe_bool 実際に変換します。

使用例

// msl_auto_gcroot_operator_bool.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" );
}
  

必要条件

ヘッダー ファイル <msclr \ auto_gcroot.h>

名前空間 の msclr

参照

関連項目

auto_gcroot::operator!

その他の技術情報

auto_gcroot Members