Created
January 11, 2013 16:56
-
-
Save pstachula-dev/4512263 to your computer and use it in GitHub Desktop.
Programowanie Obiektowe w5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class E | |
{ | |
int e; | |
public: | |
E():e(5){} | |
void get(){ cout << e << endl; } | |
}; | |
class A | |
{ | |
protected: | |
static E *e; | |
public: | |
virtual void get()=0; | |
}; | |
E * A::e = new E; | |
class B: virtual public A | |
{ | |
protected: | |
int b; | |
public: | |
B():b(20){} | |
void get(){ cout << b << endl; } | |
}; | |
class C: virtual public A | |
{ | |
protected: | |
int c; | |
public: | |
C():c(30){} | |
void get(){ cout << c << endl; } | |
}; | |
class D: public B, public C | |
{ | |
int d; | |
public: | |
D():d(40){} | |
void get() | |
{ | |
B::get(); | |
C::get(); | |
e->get(); | |
cout << d << endl; | |
} | |
}; | |
int main() | |
{ | |
A *a[3]; | |
B b; | |
C c; | |
D d; | |
a[0] = &b; | |
a[1] = &c; | |
a[2] = &d; | |
for(int i = 0; i < 3; i++) | |
a[i]->get(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment