I'm trying to make a std list that will hold a list of classes that contain a unique pointer. I keep getting an error that says attempting to reference a deleted function.
I understand that the problem is that unique pointers don't have an assignment operator and list is trying to call it, but I can't figure out a way around this.
Here is the code for the class that holds the pointer:
class ptr_hold
{
public:
ptr_hold(std::list<int>& _lst);
std::list<int>* get_list();
private:
std::unique_ptr<std::list<int>> num_list;
};
ptr_hold::ptr_hold(std::list<int>& _lst)
{
num_list = std::unique_ptr<std::list<int>>(new std::list<int>(_lst));
}
Here is the example code trying to do the assigment:
list<int> lst;
for (int i = 0; i < 5; i++)
{
lst.push_back(i);
}
ptr_hold ph = ptr_hold(lst);
list<ptr_hold> ph_list;
ph_list.push_back(ph); //error
ph_list.push_back(move(ph)); //error
How do I handle this?