std::unique_ptr::operator bool
explicit operator bool() const; | | (since C++11) |
|---|
检查是否*this拥有一个对象,即get() != nullptr...
参数
%280%29
返回值
true如果*this拥有一件物品,false否则。
例外
noexcept规格:
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';
}二次
产出:
二次
before reset, ptr is: 42二次
另见
get | returns a pointer to the managed object (public member function) |
|---|
© cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

