Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Generator.h"
- #include <list>
- class A;
- class B;
- class C;
- class Base
- {
- public:
- const int id;
- Base(const int n)
- : id(n)
- {
- }
- int GetId()
- {
- return id;
- }
- };
- class Test1 : public Base
- {
- public:
- Test1()
- : Base(TYPE_ID(Test1))
- {
- }
- };
- class Test2 : public Base
- {
- public:
- Test2()
- : Base(TYPE_ID(Test2))
- {
- }
- };
- class Test3 : public Base
- {
- public:
- Test3()
- : Base(TYPE_ID(Test3))
- {
- }
- };
- int main()
- {
- int t1 = SingleTon<A>::get(); // 0
- int t2 = SingleTon<A>::get(); // 0
- int t3 = SingleTon<B>::get(); // 1
- int t4 = SingleTon<A>::get(); // 0
- int t5 = SingleTon<B>::get(); // 1
- int t6 = SingleTon<C>::get(); // 2
- Test1 c0; // 3
- Test1 c1; // 3
- Test2 c2; // 4
- Test2 c3; // 4
- Test2 c4; // 4
- Test3 c5; // 5
- std::list<Base *> baseList;
- baseList.push_back(&c0);
- baseList.push_back(&c1);
- baseList.push_back(&c2);
- baseList.push_back(&c3);
- baseList.push_back(&c4);
- baseList.push_back(&c5);
- for(auto it = baseList.begin(); it != baseList.end(); ++it)
- {
- if((*it)->GetId() == TYPE_ID(Test1))
- {
- printf("Test1\n");
- }
- if((*it)->GetId() == TYPE_ID(Test2))
- {
- printf("Test2\n");
- }
- if((*it)->GetId() == TYPE_ID(Test3))
- {
- printf("Test3\n");
- }
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement