Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PointerVector's copy constructor/assignment can potentially introduce object slicing. #1549

Closed
Dimi1010 opened this issue Aug 25, 2024 · 0 comments · Fixed by #1550
Closed
Assignees
Labels

Comments

@Dimi1010
Copy link
Collaborator

The current implementation of PointerVector<T> contains a copy constructor/assignment that does a deep copy of all elements.

The issue is that the element wise copy is done via T* x = new T(*elemIt) which would slice off any polymorphic types held in the vector via a pointer to a base type.

A potential twofold solution can be:

  • Removal of the copy constructor/assignment of PointerVector<T>, making the class similar to a collection of std::unique_ptr.
  • Adding a SFINAE enabled clone() method, allowing the copy of the vector provided the base class T provides a clone() method.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant