模板特例化

Posted Kooing

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了模板特例化相关的知识,希望对你有一定的参考价值。

template <typename T>
class A{
private:
    T a;
public:
    A(T x) :a(x){}
    void display()
    {
        cout << a << endl;
    }
};

template<>
class A<double>
{
private:
    double a;
public:
    A(double x) :a(x){}
    void display()
    {
        cout << a <<"diao"<<endl;
    }
};

int main()
{
    double a = 3.3;
    A<double> b(a);
    A<int> c(2);
    b.display();
    c.display();
}

 

以上是关于模板特例化的主要内容,如果未能解决你的问题,请参考以下文章