Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- class B1 {
- int a;
- public:
- B1() { };
- B1(int x) { a = x; }
- void show_B1() { cout << "B1 = " << a << "\n"; }
- };
- class B2 {
- int a;
- public:
- B2() { };
- B2(int x) { a = x; }
- void show_B2() { cout << "B2 = " << a << "\n"; }
- };
- class D1 : private B1, public B2 {
- int b;
- public:
- D1(int x, int y, int z) : B1(y), B2(z) { b = x; };
- void show_D1() { cout << "D1 = " << b << "\n"; show_B1(); show_B2(); }
- };
- class D2 : public B1, private B2 {
- int c;
- public:
- D2(int x, int y, int z) : B1(y), B2(z) { c = x; };
- void show_D2() { cout << "D2 = " << c << "\n"; show_B1(); show_B2(); }
- };
- class D3 : private D1, public D2 {
- int d;
- public:
- D3(int x, int y, int z, int i, int j, int k, int l) : D1(y, z, i), D2(j, k, l) { d = x; }
- void show_D3() { cout << "D3 = " << d << "\n"; show_D1(); show_D2(); }
- };
- int main(void)
- {
- D3 temp(100, 200, 300, 400, 500, 600, 700);
- D2 temp1(1, 2, 3);
- cout << "---D3 temp(100, 200, 300, 400, 500, 600, 700)---\n";
- cout << "Class hierarchy D3: \n";
- temp.show_D3();
- cout << "\n---D2 temp1(1,2,3)---\n";
- cout << "Class hierarchy D2\n";
- temp1.show_D2();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment