65,210
社区成员
发帖
与我相关
我的任务
分享template <typename T>
struct Entry{
template <typename T>
int fun;
template <>
int fun<int>{ return 0;}; //0 为 int
template <>
int fun<double>{return 1;}//1 为 double
};template <typename T>
struct Entry{
T gettype(){return typeid(T).name;}
};
class Base
{
public:
virtual const char* work()=0;
};
template<typename T>
class A : public Base
{
public:
const char* work()
{
return typeid(T).name();
}
A():a(100){}
int a;
};
template<typename T>
class B : public Base
{
public:
const char* work()
{
return typeid(T).name();
}
B():a(99){}
int a;
};
int main()
{
g_thread_init(NULL);
GAsyncQueue * test_q;
test_q = g_async_queue_new();
Base *t2 = new B<Entry<int64_t> >;
cout<<t2->work()<<endl;;
g_async_queue_push(test_q,t2);
Base *t1 = new A<Entry<int64_t> >;
cout<<t1->work()<<endl;;
g_async_queue_push(test_q,t1);
Base *t3 = (Base*)g_async_queue_pop(test_q);
cout<<t3->work()<<endl;
}