提问人:Tharani B 提问时间:9/19/2023 最后编辑:Tharani B 更新时间:9/19/2023 访问量:58
使用 unique_ptr 提升 Bimap
Boost Bimap with unique_ptr
问:
我正在尝试将unique_ptr插入boost::bimap中,但是我收到错误“调用隐式删除的复制构造函数”。我正在通过 std::move 移动unique_ptr,并且我的类中使用 noexcept 关键字有 move 构造函数和移动赋值运算符,但插入以某种方式调用了复制构造函数。
#include <utility>
#include <boost/bimap.hpp>
class student
{
int a;
public:
explicit student(int a) : a(a) {}
student(student &&r) noexcept = default;
student &operator=(student &&other) noexcept = default;
};
int main()
{
boost::bimap<int, std::unique_ptr<student>> map;
std::unique_ptr<student> a = std::make_unique<student>(5);
map.insert({4, std::move(a)});
}
错误:-
在模板中:调用“typename base_::right_value_type”(又名“const std::unique_ptr”)的隐式删除复制构造函数
在模板中:调用“typename base_::right_value_type”(又名“std::unique_ptr”)的隐式删除复制构造函数
答: 暂无答案
评论