Is it good practice to NULL a pointer after deleting it?

后端 未结 18 1055
猫巷女王i
猫巷女王i 2020-11-22 11:28

I\'ll start out by saying, use smart pointers and you\'ll never have to worry about this.

What are the problems with the following code?

<         


        
18条回答
  •  孤独总比滥情好
    2020-11-22 11:43

    I've got an even better best practice: Where possible, end the variable's scope!

    {
        Foo* pFoo = new Foo;
        // use pFoo
        delete pFoo;
    }
    

提交回复
热议问题