Test environment:
Win7 64
g++ 4.8.1
/********************************************************************************* copyright (C), 1988-1999, Drvivermonkey. Co., ltd. file name: author:driver monkey version: Mail:[email Protected] date:2014.04.02 description: ************************************* / #include <stdlib.h> #include <iostream> #include <typeinfo> #include <typeindex> #include <map>using namespace Std;class a{ public: A () {cout<< "a created!" <<endl;}}; struct Sub_a:public a{ public: sub_a () {cout<< "Sub_a created!" <<endl;}}; Template<class T1, Class t2> class compiletimechecker { public: T1 t1; & nbsp T1 t2; Compiletimechecker () { cout<< "1---compiletimechecker = "<<typeid (t1)." Name () <<endl; cout<< "1---compiletimechecker =" <<typeid (T2). Name () <<endl; }}; template <class t> class Compiletimechecker <T,float>{ public: T t; Compiletimechecker () &nbs P { cout<< "2---compiletimechecker =" <<typeid (t). Name () <<endl; }};template<> class Compiletimechecker<a, sub_a>{ public: a a; sub_a sub_a; Compiletimechecker () &NB Sp { cout<< "3---compiletimechecker =" <<typeid (a). Name () <<endl; } }; int main (void) { compiletimechecker<int, float> int_instance; Compiletimechecker<int, int> a_instance; compiletimechecker<a,sub_a> sub_instance;}
Output Result:
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvzhjpdmvybw9ua2v5/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
Template specialization and template bias samples (templates specialization and partial templates specialization)