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

前端 未结 13 1875
礼貌的吻别
礼貌的吻别 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:12

    After deleting an object it's not defined what will happen to the contents of the memory that it occupied. It does mean that that memory is free to be re-used, but the implementation doesn't have to overwrite the data that was there originally and it doesn't have to reuse the memory immediately.

    You shouldn't access the memory after the object is gone but it shouldn't be surpising that some data remains in tact there.

提交回复
热议问题