Freigeben über


weak_ptr::expired

Testet, ob Besitz abgelaufen ist.

bool expired() const;

Hinweise

Die Memberfunktion wird true, wenn *this abgelaufen ist; andernfalls false zurück.

Beispiel

 

// std_tr1__memory__weak_ptr_expired.cpp 
// compile with: /EHsc 
#include <memory> 
#include <iostream> 
 
struct deleter 
    { 
    void operator()(int *p) 
        { 
        delete p; 
        } 
    }; 
 
int main() 
    { 
    std::weak_ptr<int> wp; 
 
     { 
    std::shared_ptr<int> sp(new int(10)); 
    wp = sp; 
    std::cout << "wp.expired() == " << std::boolalpha 
        << wp.expired() << std::endl; 
    std::cout << "*wp.lock() == " << *wp.lock() << std::endl; 
     } 
 
// check expired after sp is destroyed 
    std::cout << "wp.expired() == " << std::boolalpha 
        << wp.expired() << std::endl; 
    std::cout << "(bool)wp.lock() == " << std::boolalpha 
        << (bool)wp.lock() << std::endl; 
 
    return (0); 
    } 
 
  

Anforderungen

Header: <memory>

Namespace: std

Siehe auch

Referenz

weak_ptr-Klasse