#include <iostream> #include <map> using namespace std; template<typename T> class S { public: S() {} static T* t; static void gen() { static T p; t = &p; /* t = new T();*/ } }; class A : public S<A> { public: char carr[1024]; }; A* A::t = NULL; class B : public S<B> { public: char carr[2048]; }; B* B::t = NULL; typedef void (*func)(); // void main() { map<int, func> con; con.insert(pair<int, func>(1, A::gen)); con.insert(pair<int, func>(2, B::gen)); cout<<A::t<<endl; cout<<B::t<<endl; con[1](); con[2](); cout<<A::t<<endl; cout<<B::t<<endl; con[1](); con[2](); cout<<A::t<<endl; cout<<B::t<<endl; system("pause"); }