You are viewing a single comment's thread. Return to all comments →
Note: This is a very bad code example!
The code is producing memory leaks!!! none of the cast spells is ever deallocated in main. Do not do that! if you need a polymorphic return use std::shared_ptr and make_shared or unique_ptr and make_unique.
Very true. Also didn't think I'd see Peter Sommerlad here!
I feel like I've been seeing a lot of red flags like this in the discussion for almost every question. It does make me pretty concerned since I'm using this site to practice for interviews. Does anyone have other suggestions for websites or books to practice C++?
I know this is a bit late, but I've been using LeetCode a lot lately to practice C++. I think I like it better, especially because the discussion section is better formatted and filled with useful solutions in some of the major languages (C++, Java, Python) and a good bit of discussion on potential improvements for everyone's solutions as well as discussion of the complexities.
Yeah and naturally downcasting is a very bad practice and should be used with caution.