Suppose I have a class
class Foo { public: ~Foo() { delete &_bar; } void SetBar(const Bar& bar) { _bar = bar; } const Bar& GetBar() { return _bar; } private: Bar& _bar; }
And my use of this class is as follows (suppose Bar has a working copy constructor)
Foo f; f.SetBar(*(new Bar)); const Bar* bar = &(f.GetBar()); f.SetBar(*(new Bar(bar))); delete bar;
I have a situation like this (in the code I did not write), and when I debug the breakpoint set on the uninstall panel; I see what
&f._bar == bar
My question is this: why & f._bar and bar point to the same block of memory, and if I leave the βdelete panelβ, what are the consequences in terms of memory management?
Many thanks!
source share