Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Parent
- {
- int parentId;
- public:
- Parent(int parentIdP) : parentId{parentIdP} {}
- virtual void info() { std::cout << "I'm a Parent with pId = " << parentId << '\n'; }
- virtual ~Parent(){ std::cout << "Parent dtor\n"; }
- };
- //Parent::~Parent()
- //{
- // std::cout << "Parent dtor\n";
- //}
- class Child : public Parent
- {
- int size;
- int* arr;
- public:
- Child(int sizeP) : Parent(42), size{ sizeP }, arr{ new int[sizeP]} {}
- virtual void info()override { std::cout << "I'm a Child with size = " << size << '\n'; }
- ~Child() { delete[] arr; std::cout << "Child dtor\n"; }
- };
- int main()
- {
- //{
- // Parent p{ 33 };
- // Child c{ 10 };
- // p.info();
- // c.info();
- //}
- {
- Parent* pPtr1{ new Parent{333} };
- std::cout << "This is Parent: ";
- pPtr1->info();
- Parent* pPtr2{ new Child{5} };
- std::cout << "This is Child: ";
- pPtr2->info();
- delete pPtr1;
- delete pPtr2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement