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

前端 未结 19 901
梦谈多话
梦谈多话 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:55

    One valid use case is having to interact with legacy code. Especially if passing raw pointers to functions that take ownership of them.

    Not all libraries you use may be using smart pointers and to use them you may need to provide or accept raw pointers and manage their lifetimes manually. This may even be the case within your own codebase if it has a long history.

    Another use case is having to interact with C which does not have smart pointers.

提交回复
热议问题