Skip to content

Latest commit

 

History

History
92 lines (80 loc) · 2.03 KB

File metadata and controls

92 lines (80 loc) · 2.03 KB
title auto_handle::operator bool | Microsoft Docs
ms.custom
ms.date 11/04/2016
ms.reviewer
ms.suite
ms.technology
cpp-windows
ms.tgt_pltfrm
ms.topic reference
f1_keywords
auto_handle.operator bool
msclr.auto_handle.operator bool
operator bool
msclr::auto_handle::operator bool
auto_handle::operator bool
dev_langs
C++
helpviewer_keywords
auto_handle::operator bool
ms.assetid 2e535e99-cf87-4008-b588-02c587d77453
caps.latest.revision 12
author mikeblome
ms.author mblome
manager ghogen
translation.priority.ht
cs-cz
de-de
es-es
fr-fr
it-it
ja-jp
ko-kr
pl-pl
pt-br
ru-ru
tr-tr
zh-cn
zh-tw

auto_handle::operator bool

Operator for using auto_handle in a conditional expression.

Syntax

operator bool();  

Return Value

true if the wrapped object is valid; false otherwise.

Remarks

This operator actually converts to _detail_class::_safe_bool which is safer than bool because it cannot be converted to an integral type.

Example

// 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" );  
}  
s1 is invalid  
s2 is valid  
s2 is now invalid  

Requirements

Header file <msclr\auto_handle.h>

Namespace msclr

See Also

auto_handle Members
auto_handle::operator!