I have a class (C
) with a vector
of unique_ptr
s to an abstract class (A
) as a member. This is because C
must work with all classes of type A
, i.e. its children.
The problem is that I cannot figure out how to write a copy constructor for C
, since the type of the objects that the pointers are pointing to are not known at compile time. It actually seems impossible to me. Can anyone confirm that it is impossible? Do you have any suggestions on how to solve the problem? Is it too awful to have a class without a copy constructor?
unique_ptr
doesn't have it as you may have noticed. – Expulsivevirtual A* clone() = 0;
toA
. – JankowskiC
to be copy constructible. There's nothing wrong with having non-copyable classes, it depends entirely on your use case. – Ladogaunique_ptr
s then the only way is thatA
will have to include a cloning function. – Eliaseliason