C+删除-它删除我的对象,但我仍然可以访问数据?
class SingleBlock{ public: SingleBlock(int, int); ~SingleBlock(); int x; int y; SingleBlock *next;};class MultiBlock{ public: MultiBlock(int, int); SingleBlock *c, *d, *e, *f;};SingleBlock::SingleBlock(int a, int b){ x = a; y = b;}SingleBlock::~SingleBlock(){ x = 222;}MultiBlock::MultiBlock(int a, int b){ c = new SingleBlock (a,b); d = c->next = new SingleBlock (a+10,b); e = d->next = new SingleBlock (a+20,b); f = e->next = new SingleBlock (a+30,b);}
SingleBlock *deleteBlock;SingleBlock *tempBlock;tempBlock = deleteBlock->next;delete deleteBlock;
Existing Blocks:
Block: 00E927A8
Block: 00E94290
Block: 00E942B0
Block: 00E942D0
Block: 00E942F0
Block: 00E94500
Block: 00E94520
Block: 00E94540
Block: 00E94560
Block: 00E945B0
Block: 00E945D0
Block: 00E945F0
Block: 00E94610
Block: 00E94660
Block: 00E94680
Block: 00E946A0
Deleting Blocks:
Deleting ... 00E942B0, X = 15288000
Deleting ... 00E942D0, X = 15286960
Deleting ... 00E94520, X = 15286992
Deleting ... 00E94540, X = 15270296
Deleting ... 00E94560, X = 222
Deleting ... 00E945D0, X = 15270296
Deleting ... 00E945F0, X = 222
Deleting ... 00E94610, X = 222
Deleting ... 00E94660, X = 15270296
Deleting ... 00E94680, X = 222
是否能够访问预期之外的数据?
对不起,如果这是一个长的喘息。
收到一只叮咚
呼唤远方
江户川乱折腾