[ Web Proxy ]
URL:
Viewing: http://ru.cppreference.com/cpp/memory/shared_ptr/operator_bool [Back]  [Original]

std::shared_ptr::operator bool cppreference.com
cppreference.com

std::shared_ptr::operator bool

cppreference.com
 
C++
(C++20)
(C++20)
(C++11)
(C++20)
/
(C++11)
(C++11)
(C++11)
(C++17)
 
 
no section name
no section name
(C++11)( C++23)
(C++11)( C++23)
(C++11)( C++23)
(C++11)( C++23)
(C++11)( C++23)
(C++11)( C++23)



no section name
 
 
<tbody> </tbody>
explicit operator bool() const noexcept;

, *this , get() != nullptr.

()

true, *this , false .

shared_ptr ( use_count() == 0) , get(), .

#include <iostream>
#include <memory>

void report(std::shared_ptr<int> ptr) 
{
    if (ptr) {
        std::cout << "*ptr=" << *ptr << "\n";
    } else {
        std::cout << "ptr    .\n";
    }
}

int main()
{
    std::shared_ptr<int> ptr;
    report(ptr);

    ptr = std::make_shared<int>(7);
    report(ptr);
}

:

ptr    .
*ptr=7


(public -) []

Web Proxy Viewer  |  New URL  |  Original Page