auto_handle::operator bool

运算符用于 auto_handle 一个条件表达式。

operator bool();

返回值

true ,如果被包装的对象是有效的;否则 false 。

备注

比 bool 安全的此运算符实际转换为 _detail_class::_safe_bool ,因为它不能转换为整型。

示例

// msl_auto_handle_operator_bool.cpp
// compile with: /clr
#include <msclr\auto_handle.h>

using namespace System;
using namespace msclr;

int main() {
   auto_handle<String> s1;
   auto_handle<String> s2 = "hi";
   if ( s1 ) Console::WriteLine( "s1 is valid" );
   if ( !s1 ) Console::WriteLine( "s1 is invalid" );
   if ( s2 ) Console::WriteLine( "s2 is valid" );
   if ( !s2 ) Console::WriteLine( "s2 is invalid" );
   s2.reset();
   if ( s2 ) Console::WriteLine( "s2 is now valid" );
   if ( !s2 ) Console::WriteLine( "s2 is now invalid" );
}
  

要求

头文件 <msclr \ auto_handle.h>

命名空间 msclr

请参见

参考

auto_handle::operator!

其他资源

auto_handle Members