测试资源是否存在。
operator boolean-type() const;
备注
运算符返回是转换为 bool类型的值。 转换的结果。bool 的类型为 true 时,get() != 0,否则为 false。
示例
// std_tr1__memory__shared_ptr_operator_bool.cpp
// compile with: /EHsc
#include <memory>
#include <iostream>
int main()
{
std::shared_ptr<int> sp0;
std::shared_ptr<int> sp1(new int(5));
std::cout << "(bool)sp0 == " << std::boolalpha
<< (bool)sp0 << std::endl;
std::cout << "(bool)sp1 == " << std::boolalpha
<< (bool)sp1 << std::endl;
return (0);
}
要求
页眉: <内存>
命名空间: std