Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class A {
- public:
- virtual ~A() {}
- void f();
- virtual void g() { cout << "A::g" << endl; }
- private:
- int x;
- };
- void A::f()
- {
- cout << "A::f" << endl;
- }
- class B {
- public:
- B();
- virtual ~B() {}
- void special() { h(); }
- // Можно сделать чисто виртуальной.
- virtual void h() { cout << "B::h" << endl; }
- };
- B::B()
- {
- special();
- }
- class C : public A, public B {
- public:
- C();
- virtual ~C() {}
- void f() { cout << "C::f" << endl; }
- virtual void g() { cout << "C::g" << endl; }
- virtual void h() { cout << "C::h" << endl; }
- };
- C::C() :
- A(),
- B()
- {
- }
- int main()
- {
- A* a = new A();
- a->f();
- cout << sizeof( A ) << endl;
- delete a;
- C* c2 = new C();
- A* a2 = c2;
- B* b2 = c2;
- a2->f();
- b2->h();
- delete a2;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement