Using std::shared_ptr to point to anything

后端 未结 4 1964
醉梦人生
醉梦人生 2020-12-16 23:42

I\'m using a std::shared_ptr in my application to make a smart pointer which can point to many different types of data structures like structs, vect

4条回答
  •  余生分开走
    2020-12-17 00:22

    This is not good practice. If you don't store additional type information next to your std::shared_ptr (which you can cast using static_pointer_cast) you have undefined behaviour all around. Maybe Boost.Any is an option for you?

    If you want to stick with std::shared_ptr please remember to provide a custom deleter function (see make shared_ptr not use delete).

提交回复
热议问题