pros and cons of smart pointers

前端 未结 10 1939
长情又很酷
长情又很酷 2021-02-05 05:31

I came to know that smart pointer is used for resource management and supports RAII.

But what are the corner cases in which smart pointer doesn\'t seem smart and things

10条回答
  •  粉色の甜心
    2021-02-05 06:23

    Many people run into problems when using smart pointers mixed with raw pointers (to the same objects). A typical example is when interacting with an API that uses raw pointers.
    For example; in boost::shared_ptr there is a .get() function that returns the raw pointer. Good functionality if used with care, but many people seem to trip on it.
    IMHO it's an example of a "leaky abstraction".

提交回复
热议问题