Are there any valid use cases to use new and delete, raw pointers or c-style arrays with modern C++?

前端 未结 19 1218
梦谈多话
梦谈多话 2020-11-22 07:20

Here\'s a notable video (Stop teaching C) about that paradigm change to take in teaching the c++ language.

And an also notable blog post

19条回答
  •  情歌与酒
    2020-11-22 07:46

    Another use case may be 3rd party library returning raw pointer which is internally covered by own intrusive reference counting (or own memory management - which is not covered by any API/user interface).

    Good example is OpenSceneGraph and their implementation of osg::ref_ptr container and osg::Referenced base class.

    Although it may be possible to use shared_ptr, the intrusive reference counting is way better for scene graph like use cases.

    Personally I do see anything "smart" on the unique_ptr. It is just scope locked new & delete. Although shared_ptr looks way better, it requires overhead which is in many practical cases unacceptable.

    So in general my use case is:

    When dealing with non-STL raw pointer wrappers.

提交回复
热议问题