Template specialization and template bias samples (templates specialization and partial templates specialization)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.