Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- class Parent
- {
- protected:
- int my_num;
- public:
- Parent(int my_num)
- {
- this->my_num = my_num;
- }
- // virtual
- void eat()
- {
- std::cout << this->my_num << std::endl;
- }
- };
- class Child : Parent
- {
- public:
- Child(int my_num) : Parent(my_num)
- {
- }
- void eat()
- {
- std::cout << "child: " << this->my_num << std::endl;
- }
- };
- void dummy_fun(Parent* p)
- {
- p->eat();
- }
- int main()
- {
- Parent* p = new Parent(4);
- Child* c = new Child(5);
- dummy_fun(p);
- dummy_fun((Parent*) c);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement