本文共 675 字,大约阅读时间需要 2 分钟。
unique_ptr 是 C++ 11 提供的用于防止内存泄漏的智能指针中的一种实现,独享被管理对象指针所有权的智能指针。
int main(){ std::unique_ptr num(new int(23)); cout << *num << endl; return 0;}
std::move是将对象的状态或者所有权从一个对象转移到另一个对象,只是转移,没有内存的搬迁或者内存拷贝所以可以提高利用效率,改善性能.。
get函数会返回存储的指针。如果由unique_ptr不为空,则存储的指针指向由unique_ptr管理的对象,否则指向nullptr。#include#include #include #include #include
运行结果:
value=23 addr=0x5583e82e2e70value=23 addr=0x5583e82e2e70
转载地址:http://oafab.baihongyu.com/