Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- class Parent
- {
- int id;
- public:
- Parent(int idP)
- : id{ idP }
- { std::cout << "Parent constructed for " << this << " with id = " << id << '\n'; };
- Parent() : Parent{ 0 } {};
- ~Parent() { std::cout << "Parent destructed for " << this << " with id = " << id << '\n'; }
- int getId() const { return id; };
- Parent& setId(int idP) { id = idP; return *this; };
- };
- class Child : public Parent
- {
- int val;
- public:
- Child(int valP, int idP)
- : Parent{ idP }, val{ valP }
- {
- std::cout << "Child constructed for "
- << this << " with id = " << getId() << " val = " << val << '\n';
- };
- Child() : Child{ 0, 0 } {};
- ~Child()
- {
- std::cout << "Child destructed for "
- << this << " with id = " << getId() << " val = " << val << '\n';
- }
- };
- int main()
- {
- std::cout << "Parent...\n";
- Parent p;
- std::cout << "Child...\n";
- Child c;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement