Advertisement
yorath

cpp

Dec 26th, 2011
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Base {
  5.     int a, b;
  6. public:
  7.     Base(int x, int y) {
  8.         a = x;
  9.         b = y;
  10.     }
  11.     void show() {
  12.         cout << "Base" << endl;
  13.         cout << a << '\t' << b << endl;
  14.     }
  15. };
  16.  
  17. class Derived: public Base {
  18.     int c, d;
  19. public:
  20.     Derived(int x, int y, int z, int m) :Base(x, y) {
  21.         c = z;
  22.         d = m;
  23.     }
  24.     void show() {
  25.         cout << "Derived" << endl;
  26.         cout << c << 't' << d << endl;
  27.     }
  28. };
  29.  
  30. int main() {
  31.     Base B1(50, 50), *pb;
  32.     Derived D1(10, 20, 30, 40);
  33.     pb = &D1;
  34.     pb->show();
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement