使用相同的unique_ptr执行两次std :: move两次

问题描述 投票:0回答:1

如果我使用相同的unique_ptr两次调用std :: move会发生什么?

unique_ptr<int> foo(new int(5));
unique_ptr<int> bar = move(foo);
unique_ptr<int> baz = move(foo);
c++ move unique-ptr
1个回答
1
投票

unique_ptr移动将其保留为空。因此,baz也将最终为null。

© www.soinside.com 2019 - 2024. All rights reserved.