Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "iostream";
- using namespace std;
- //class A
- class A
- {
- A* next;
- static A* list;
- protected:
- int nr;
- public:
- A (int n) {nr = n; next = list; list = this;} //WHAT HAPPENS HERE ???
- ~A() {};
- virtual void f() { cout << "A::f " << nr << endl; }
- static void printList();
- };
- A* A::list = NULL;
- void A::printList()
- {
- for (A* p = list; p ; p = p->next)
- p->f();
- cout << "\n";
- }
- //class B
- class B : public A
- {
- char* name;
- public:
- B(int n, char* str) : A(n), name(str) {}
- virtual void f() { cout << "B::f " << nr << " " << name << endl;}
- };
- int _tmain(int argc, _TCHAR* argv[])
- {
- A a1(10), a2(20), a3(30);
- B bl(44, "b1"), b2(55, "b2");
- A a(60);
- A::printList();
- char f;
- cin >> f;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement