Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //============================================================================
- // Name : 1stt.cpp
- // Author :
- // Version :
- // Copyright : Your copyright notice
- // Description : Hello World in C++, Ansi-style
- //============================================================================
- #include <iostream>
- #include <string>
- using namespace std;
- class C
- {
- public:
- virtual void show_value()=0;
- virtual ~C(){};
- };
- class B : virtual public C
- {
- char x;
- public:
- B(){x='s';}
- char get_x(){
- return x;
- }
- void show_value()
- {
- cout << this->x << endl;
- }
- };
- class A : virtual public C
- {
- private:
- const int a;
- string str;
- static B * ptr;
- public:
- A(): a(2), str("string"){};
- static void b_create()
- {
- ptr = new B();
- }
- static void show()
- {
- cout << "Metoda statyczna: " << ptr-> get_x() << endl;
- }
- static void b_delete()
- {
- delete ptr;
- }
- int get_a() const
- {
- return a;
- }
- string get_str() const
- {
- return str;
- }
- void set_a(int b)
- {
- // a=b;
- }
- void set_str(string s)
- {
- str = s;
- }
- void show_value()
- {
- cout << this->a << ", " << this->str << endl;
- }
- };
- class X: public A, public B
- {
- int x;
- public:
- X(){x = 255;}
- void show_value()
- {
- cout <<endl<< this->x << endl;
- }
- };
- void set(A **&tab, int size)
- {
- for(int i=0; i<size; i++)
- {
- tab[i]->set_str("nowy string");
- }
- }
- void set(A tab[], int size)
- {
- for(int i=0; i<size; i++)
- {
- tab[i].set_str("stat tablica");
- }
- }
- void create(A** &tab, int size)
- {
- tab = new A*[size];
- for(int i=0; i<size; i++)
- {
- tab[i] = new A();
- }
- }
- void show(A**&tab, int size)
- {
- for(int i=0; i<size; i++)
- {
- cout << tab[i]->get_a() << endl;
- cout << tab[i]->get_str() << endl;
- }
- }
- void show(A tab[], int size)
- {
- for(int i=0; i<size; i++)
- {
- cout << tab[i].get_str() << endl;
- cout << tab[i].get_a() << endl;
- }
- }
- void remove(A ** &tab, int size)
- {
- for(int i=0; i<size; i++)
- {
- delete tab[i];
- }
- delete [] tab;
- }
- B *A::ptr = NULL;
- int main() {
- int size = 3;
- A::b_create();
- //
- A::show();
- A::b_delete();
- A ** a;
- A tab[size];
- create(a, size);
- show(tab,size);
- show(a,size);
- set(a, size);
- show(a,size);
- set(tab,size);
- show(tab,size);
- cout << "poliformfizm" << endl << endl;
- C **tb = new C*[3];
- tb[0] = new A();
- tb[1] = new B();
- tb[2] = new X();
- for(int i=0;i<size;i++)
- {
- tb[i]->show_value();
- }
- cout << "poliformfizm" << endl << endl;
- C* pointer = NULL;
- pointer = new A();
- pointer->show_value();
- pointer = new B();
- pointer->show_value();
- pointer = new X();
- pointer->show_value();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement