Why auto ptr deprecated




















I was actually asked a question around this topic in an interview a few years ago. In quantitative finance, this might be a vector of derivative contracts, for instance.

One bad way to achieve this is by using a container of pointers to the option object. If the code prior to delete vec. Why is this? Simply, because although the destructor called by std::vector , it does NOT remove the allocations that were made by the new operator, when creating the Option object. Although the above code will compile and run, it is bad practice to use such containers of "dumb" pointers due to the fragility of the function.

The solution to such a problem is to use a smart pointer. Let's modify the function prototype code above to make use of it:. Star New issue. Jump to bottom. Copy link. Fair enough. I'll see what I can do. Thanks, if you want me to submit a PR for this issue let me know. Let me see what I can do and submit a PR for this. Also seeing this. Treat it separately? Feel free to include it into the same PR, but make it a separate commit.

Sign up for free to join this conversation on GitHub. Reference Counting: It is a technique of storing the number of references, pointers or handles to a resource such as an object, block of memory, disk space or other resources. An object referenced by the contained raw pointer will not be destroyed until reference count is greater than zero i. In general, it is a design issue. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.

See your article appearing on the GeeksforGeeks main page and help other Geeks. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above. Skip to content. Change Language. Related Articles. Save Article. Improve Article.



0コメント

  • 1000 / 1000