std::shared_ptr::operator bool
cppreference.com
<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 -) |