Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Base1
- {
- public:
- Base1(int a = 0)
- {
- p = a; q = a + 1;
- cout << "Base1: " << p << "," << q << endl;
- }
- Base1(const Base1& r)
- {
- cout << "Base1.p: " << r.p << endl
- << "Base1.q: " << r.q << endl;
- }
- Base1& operator=(const Base1& r)
- {
- if (this != &r)
- {
- p = r.p + 1;
- q = r.q + 2;
- cout << "Base1.p: " << p << endl
- << "Base1.q: " << q << endl;
- }
- return *this;
- }
- ~Base1()
- {
- cout << "~Base1()\n";
- }
- private:
- int p, q;
- };
- class Base2
- {
- public:
- Base2(int b = 0)
- {
- p = b; q = b + 1;
- cout << "Base2: " << p << "," << q << endl;
- }
- Base2(const Base2& r)
- {
- p = r.p + 1;
- q = r.q + 2;
- cout << "Base2.p: " << p << endl
- << "Base2.q: " << q << endl;
- }
- ~Base2()
- {
- cout << "~Base2()\n";
- }
- protected:
- int p, q;
- };
- class Der : protected Base2, public Base1
- {
- public:
- Der(int a = 2, int b = 1, int c = 1) : Base1(a), Base2(b), m(1)
- {
- p = c; q = a - b;
- n = Base2(8);
- cout << "Der: " << p << "," << q << endl;
- }
- Der(const Der& r)
- {
- cout << "Der::Der(const Der& r)\n";
- p = r.p + 3; q = r.q + 2;
- cout << "Der.p: " << p << endl
- << "Der.q: " << q << endl;
- }
- Der& operator=(const Der& r)
- {
- cout << "Der::operator=()\n";
- if (this != &r)
- {
- Base1::operator=(r);
- Base2::p = r.p + 1;
- Base2::q = r.q + 2;
- p = r.p; q = r.q;
- m = r.m;
- n = r.n;
- }
- return *this;
- }
- ~Der()
- {
- cout << "~Der()\n";
- }
- private:
- int p, q;
- Base1 m;
- Base2 n;
- };
- int main()
- {
- Der x(1, 3, 5), y(2, 4);
- Der z = x;
- z = y;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement