C++ delete - It deletes my objects but I can still access the data?

前端 未结 13 1889
礼貌的吻别
礼貌的吻别 2020-11-21 06:11

I have written a simple, working tetris game with each block as an instance of a class singleblock.

class SingleBlock
{
    public:
    SingleBlock(int, int)         


        
13条回答
  •  暖寄归人
    2020-11-21 07:02

    It will lead to undefined behaviour and delete deallocates memory , it does not reinitialize it with zero .

    If you want to make it zero out then do :

    SingleBlock::~SingleBlock()
    
    {    x = y = 0 ; }
    

提交回复
热议问题