模板特例化

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();
}

 

posted on 2016-06-20 21:15  Kooing  阅读(118)  评论(0编辑  收藏  举报

导航