explicit operator bool() const; | (since C++11) |
Checks whether *this
owns an object, i.e. whether get() != nullptr
.
(none).
true
if *this
owns an object, false
otherwise.
noexcept
specification: noexcept
#include <iostream> #include <memory> int main() { std::unique_ptr<int> ptr(new int(42)); if (ptr) std::cout << "before reset, ptr is: " << *ptr << '\n'; ptr.reset(); if (ptr) std::cout << "after reset, ptr is: " << *ptr << '\n'; }
Output:
before reset, ptr is: 42
returns a pointer to the managed object (public member function) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/memory/unique_ptr/operator_bool