/** * Draw the memory diagram at each statement executed. * Warning: this code is buggy! */ #include #include #include "./IntArrayList.h" class Wrap { public: Wrap() : p_(nullptr) {} Wrap(IntArrayList *p) : p_(p) { *p_ = *p; } IntArrayList *p() const { return p_; } private: IntArrayList *p_; }; struct List { IntArrayList v; }; void func(Wrap x) { std::cout << "Wrap x wraps " << x.p() << std::endl; } int main() { Wrap a; Wrap b(new IntArrayList); struct List c { }; struct List d { *b.p() }; a = b; c = d; func(a); Wrap *e; e = &a; Wrap *f = new Wrap(&d.v); struct List *g = new struct List; g->v = *(new IntArrayList); delete f; delete g; return 0; }