运算符用于 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