Advertisement
pranto_95

Virtual function

Oct 27th, 2015
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. class P1{
  4. public:
  5.     virtual void display(){
  6.     cout<<"Count the valu"<<endl;
  7.     }
  8.     };
  9.     class P2: public P1{
  10.         void display(){
  11.         cout<<"Count the second value"<<endl;
  12.         }
  13.    };
  14.    class P3:public P1{
  15.    void display(){
  16.    cout<<"Count value"<<endl;
  17.    }
  18.    };
  19.    int main(){
  20.    P1 *p;
  21.    P2 q;
  22.    P3 r;
  23.    p=&q;
  24.    p->display();
  25.    p=&r;
  26.    p->display();
  27.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement