auto_gcroot::operator bool
運算子使用auto_gcroot條件運算式中。
operator bool() const;
傳回值
true如果被包裝的物件是有效的。 false否則。
備註
實際上,此運算子會轉換成_detail_class::_safe_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" );
}
需求
標頭檔 <msclr\auto_gcroot.h>
Namespace msclr