I'm working on my little project about pointers, I ran into problem when I was trying to push a unique_ptr to a derived class, to a vector of unique_ptr to base class. It keeps saying that I'm "attempting to reference to a deleted function". I tried to use push_back with and without std::move but nothing worked...
#include<iostream>
#include<memory>
#include<vector>
using namespace std;
class Base {};
class Derived : public Base {};
void add(vector<unique_ptr<Base>> list, const unique_ptr<Base>& ptr);
int main()
{
vector<unique_ptr<Base>> list;
unique_ptr<Base> derived(new Derived);
add(list, derived);
}
void add(vector<unique_ptr<Base>> list, const unique_ptr<Base>& ptr)
{
list.push_back(move(ptr));
}