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

前端 未结 13 1844
礼貌的吻别
礼貌的吻别 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 06:56

    Although it's possible that your runtime doesn't report this error, using a proper error-checking runtime such as Valgrind will alert you to the use of memory after it has been freed.

    I recommend that if you write code with new/delete and raw pointers (rather than std::make_shared() and similar), that you exercise your unit tests under Valgrind to at least have a chance of spotting such errors.

提交回复
热议问题