37 lines · cpp
1#include <stdio.h>2#include <memory>3 4class BaseClass5{6public:7 BaseClass();8 virtual ~BaseClass() { }9};10 11class DerivedClass : public BaseClass12{13public:14 DerivedClass();15 virtual ~DerivedClass() { }16protected:17 int mem;18};19 20BaseClass::BaseClass()21{22}23 24DerivedClass::DerivedClass() : BaseClass()25{26 mem = 101;27}28 29int30main (int argc, char **argv)31{32 BaseClass *b = nullptr; // Break here and check b has 0 children33 b = new DerivedClass(); // Break here and check b still has 0 children34 b = nullptr; // Break here and check b has one child now35 return 0; // Break here and check b has 0 children again36}37