我有如下代码
std::vector<std::unique_ptr<int>> v;
std::unique_ptr<int> a(new int(0));
std::unique_ptr<int>& b = a;
v.insert(v.begin(), std::move(b)); //ok
但是,如果我在第三条语句中添加 const
const std::unique_ptr<int>& b = a;
v.insert(v.begin(), std::move(b)); //Compiler error, cannot access ptr private member
为什么编译器显示它不能访问唯一指针的私有成员,除了不能将 const 转换为非常量?谢谢。