Advertisement
aurko96

class_virtual

May 6th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. class base
  4. {
  5.     int b;
  6. public:
  7.     base(){}
  8.     base(int b)
  9.     {
  10.         this->b=b;
  11.         cout<<"Inside base having "<<this->b<<endl;
  12.     }
  13. };
  14. class base2
  15. {
  16.     int bb;
  17. public:
  18.     base2(){}
  19.     base2(int bb)
  20.     {
  21.         this->bb=bb;
  22.         cout<<"Inside base_2 having "<<this->bb<<endl;
  23.     }
  24.     virtual void print_data(int x)=0;
  25. };
  26. class der1:virtual public base,public base2
  27. {
  28.     int d;
  29. public:
  30.     der1(){}
  31.     der1(int c,int d):base(c)
  32.     {
  33.         this->d=d;
  34.         cout<<"Inside derieved_A having "<<this->d<<endl;
  35.     }
  36.     void print_data(int x)
  37.     {
  38.         cout<<"Inside pure virtual function in derieved_A from abstract base_2 having "<<x<<endl;
  39.     }
  40. };
  41. class der2:public base
  42. {
  43.     int e;
  44. public:
  45.     der2(){}
  46.     der2(int e,int f):base(f)
  47.     {
  48.         this->e=e;
  49.         cout<<"Inside derieved_B having "<<this->e<<endl;
  50.     }
  51. };
  52. class der3:public der1,public der2
  53. {
  54.     int a;
  55. public:
  56.     der3(){}
  57.     der3(int a,int b,int c,int d,int e):der1(b,c),der2(d,e)
  58.     {
  59.         this->a=a;
  60.         cout<<"Inside derieved_C having "<<this->a<<endl;
  61.     }
  62. };
  63. int main()
  64. {
  65.     der3 obj(5,6,7,8,9);
  66.     base2 *ptr;
  67.     der1 ob2;
  68.     ptr=&ob2;
  69.     ptr->print_data(250);
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement