条件式内で auto_gcroot を使用するための演算子。
operator bool() const;
戻り値
ラップされたオブジェクトが有効な場合は true、それ以外の場合は false です。
解説
この演算子は、実際には _detail_class::_safe_bool に変換されます。bool は整数型に変換できないので 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" );
}
s is invalid
now s is valid
now s is invalid
必要条件
ヘッダー ファイル <msclr\auto_gcroot.h>
名前空間 msclr