Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Glowna
- {
- int a;
- int b;
- public:
- Glowna(int z, int y):a(z),b(y) {}
- };
- class Pochodna1 : public Glowna
- {
- int c;
- public:
- Pochodna1():Glowna(1,2),c(3) {}
- };
- class Pochodna2 : public Glowna
- {
- int d;
- public:
- Pochodna2():Glowna(4,5),d(6) {}
- int Metoda() { return d; }
- };
- class Pochodna3 : public Glowna
- {
- int e;
- public:
- Pochodna3():Glowna(7,8),e(9) {}
- };
- int main()
- {
- Glowna *tablica = new Glowna[3];
- Glowna *wskaznik = new Pochodna1();
- tablica[0] = *wskaznik;
- Glowna *wskaznik = new Pochodna2();
- tablica[1] = *wskaznik;
- Glowna *wskaznik = new Pochodna3();
- tablica[2] = *wskaznik;
- for (int i = 0; i < 3; i++)
- {
- if (tablica[i].a == 4)
- {
- //tutaj wywołać metodę Metoda() z klasy Pochodna2.
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement