Medium
weak_ptr::lock after the owning shared_ptr goes out of scope
What does this program print?
main.cpp
#include <iostream>
#include <memory>
int main() {
std::weak_ptr<int> wp;
{
auto sp = std::make_shared<int>(42);
wp = sp;
}
if (auto locked = wp.lock()) {
std::cout << *locked << std::endl;
} else {
std::cout << "expired\n";
}
}17 of 117 in C++