In the following code, the assertion in foo is failing:
void bar (std::shared_ptr<int> && value) {
}
void foo () {
auto ptr = std::make_shared<int>(5);
bar(std::move(ptr));
assert(ptr == nullptr);
}
The shared pointer still points to the value 5 after the call to bar. I expected the call to bar to use move semantics, leaving ptr null. Where is the flaw in my understanding?
Aucun commentaire:
Enregistrer un commentaire