📅  最后修改于: 2022-03-11 14:44:52.853000             🧑  作者: Mango
#include
#include
void report(std::shared_ptr ptr) {
if (ptr) {
std::cout << "*ptr=" << *ptr << "\n";
} else {
std::cout << "ptr is not a valid pointer.\n";
}
}
int main() {
std::shared_ptr ptr;
report(ptr);
ptr = std::make_shared(7);
report(ptr);
}
//output:
//ptr is not a valid pointer.
//*ptr=7