Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class A{
- public:
- virtual void print(){
- cout<<"A"<<endl;
- }
- };
- class B:public A{
- public:
- void print(){
- cout<<"B"<<endl;
- }
- };
- class C:public A{
- public:
- void print(){
- cout<<"C"<<endl;
- }
- };
- int Cpp(){
- static int c=0;
- c++;
- return c;
- }
- class qwerty{
- public:
- static int count;
- qwerty(){
- cout << "Constructor is called" << endl;
- qwerty::count++;
- }
- static int getCount(){
- return qwerty::count;
- }
- };
- int qwerty::count = 0;
- int main()
- {
- A **ptr=new A*[10];
- for (int i=0;i<4;i++){
- ptr[i]=new A();
- }
- for (int i=4;i<8;i++){
- ptr[i]=new B();
- }
- for (int i=8;i<10;i++){
- ptr[i]=new C();
- }
- for (int i=0;i<10;i++){
- ptr[i]->print();
- }
- for (int i=0;i<5;i++){
- cout<<Cpp()<<endl;
- }
- qwerty a;
- qwerty b;
- cout << qwerty::getCount() << endl;
- }
Add Comment
Please, Sign In to add comment