Error case (why does the destructor of class A will be called by twice?):
class A {};
std::unique_ptr<A>&& get() {
std::unique_ptr<A> p(new A());
return std::move(p);
}
int main() {
std::unique_ptr<A> k = get();
}
Normal Case:
class A {};
std::unique_ptr<A> get() {
std::unique_ptr<A> p(new A());
return std::move(p);
}
int main() {
std::unique_ptr<A> k = std::move(get());
}
Aucun commentaire:
Enregistrer un commentaire