std::shared_ptr::operator bool - cppreference.com (original) (raw)

| explicit operator bool() const noexcept; | | | | ---------------------------------------- | | |

Checks if *this stores a non-null pointer, i.e. whether get() != nullptr.

[edit] Parameters

(none)

[edit] Return value

true if *this stores a pointer, false otherwise.

[edit] Notes

An empty shared_ptr (where use_count() == 0) may store a non-null pointer accessible by get(), e.g. if it were created using the aliasing constructor.

[edit] Example

Output:

ptr is not a valid pointer. *ptr=7

[edit] See also

| | returns the stored pointer (public member function) [edit] | | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |