且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C ++-返回const unique_ptr

更新时间:2023-11-13 13:58:16

由于 unique_ptr 是常量,因此只能复制而不能移动。并且不允许复制 unique_ptr (否则将不是唯一)。

Because the unique_ptr is constant it can not be moved only copied. And copying a unique_ptr is not allowed (otherwise it would not be "unique").

如果数据指向指针所指向的值应该是常量,然后使用 std :: unique_ptr< const int> 代替。

If the data pointed to by the pointer should be constant, then use std::unique_ptr<const int> instead.