Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Object slicing doesn't occur when pointers or references to objects are passed as function arguments since both the pointers are of the same size.
- #include <iostream>
- using namespace std;
- class Base {
- public:
- Base(long ss) : ss_num(ss) { }
- long ss_num;
- virtual void dispaly()
- {
- cout << "base" << ss_num;
- }
- };
- class Derived : public Base {
- public:
- Derived(long social, float pay) : Base(social), pay_rate(pay) { }
- virtual void dispaly()
- {
- cout << "Derived" << pay_rate << " " << ss_num;
- }
- float pay_rate;
- };
- void test(Base& test)
- {
- test.dispaly();
- }
- int main() {
- Base bp(33);
- Derived dp(45, 54);
- Base &test = dp;
- bp = dp;
- test.dispaly();
- cout << endl;
- bp.dispaly();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement