Udostępnij za pośrednictwem


shared_ptr::operator boolean-type

Testy, jeśli istnieje posiadanych zasobów.

operator boolean-type() const;

Uwagi

Operator zwraca wartość typu, który jest konwertowany na bool.Wynik konwersji na bool jest true po get() != 0, w przeciwnym razie false.

Przykład

 

// std_tr1__memory__shared_ptr_operator_bool.cpp 
// compile with: /EHsc 
#include <memory> 
#include <iostream> 
 
int main() 
    { 
    std::shared_ptr<int> sp0; 
    std::shared_ptr<int> sp1(new int(5)); 
 
    std::cout << "(bool)sp0 == " << std::boolalpha 
        << (bool)sp0 << std::endl; 
    std::cout << "(bool)sp1 == " << std::boolalpha 
        << (bool)sp1 << std::endl; 
 
    return (0); 
    } 
 
  

Wymagania

Nagłówek: <memory>

Obszar nazw: std

Zobacz też

Informacje

shared_ptr Class

shared_ptr::get