0
How do you prevent object slicing in C++?
How do you prevent object slicing in C++ without using pointers to objects? Please let me know ;) thanks in advance
2 ответов
+ 3
A fellow dutchman, hi :)
You can't, you have to use pointers to use polymorphism.
Don't forget to mark your destructor as virtual though.
Read up about unique_ptr and shared_ptr if you're worried about deletion.
https://en.cppreference.com/w/cpp/memory/unique_ptr
https://en.cppreference.com/w/cpp/memory/shared_ptr
0
Thanks Dennis!