My class contains a unique pointer to an array. When the copy constructor is called, I want the class to create its own unique pointer array and just copy the contents of the old unique pointer array. I keep getting errors about converting from a const value, and I'm not sure how to get around it.
My pointer is declared under private like this:
std::unique_ptr<Manager[]> managers;
I planned to just loop through the array and copy manually, so I made this copy constructor:
Restaurant::Restaurant(const Restaurant &_r)
{
Manager *_managers = _r.managers;
for (int i = 0; i < MAX_MANAGERS; i++)
{
managers.get()[i] = _managers[i];
}
}
It gives the const convert error on this line:
Manager *_managers = _r.managers;
I just want to make a deep copy. How can I go about it to make this work?
_r.managers
a unique_ptr? You can't assign it to something else.std::vector<Manager>
be better suited?unique_ptr
you have to do the copy manually, which means writing a copy constructor and copy assignment.vector
has one built-in, so you don't have to write either of those.