The memory leaks section just feels like an introduction to smart pointers as though they’re some complex concept. Also, the page is showing its age by mentioning the now-removed auto_ptr instead of something like unique_ptr.
Anyway, scrolling down a little more:
Why can’t I assign a vector<Apple*> to a vector<Fruit*>?
The memory leaks section just feels like an introduction to smart pointers as though they’re some complex concept. Also, the page is showing its age by mentioning the now-removed
auto_ptrinstead of something likeunique_ptr.Anyway, scrolling down a little more:
This actually comes up in C# with arrays. Copying their example here:
It may have been a design mistake not to make C#'s arrays invariant, though I don’t know the state of that debate today.