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

21st May 2020, 2:17 PM
Orville Vroemen
Orville Vroemen - avatar
2 odpowiedzi
+ 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
21st May 2020, 2:39 PM
Dennis
Dennis - avatar
0
Thanks Dennis!
21st May 2020, 2:58 PM
Orville Vroemen
Orville Vroemen - avatar