Calling push_back
like that will attempt to copy the unique_ptr
into the vector. You can't copy unique_ptr
s! Instead, you need to move it into the vector:
EmpVect.push_back(std::move(TempEmp));
You do, however, have another problem. Your unique_ptr
is not initialised to point at any particular allocated Employee
, yet you then try to assign to that object. That's not good. Instead, you should dynamically allocate the Employee
and pass it to the unique_ptr
constructor:
unique_ptr<Employee> TempEmp(new Employee());
Or preferably, use an implementation of std::make_unique
(which will be available in C++14).