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(); }
时间: 2024-11-13 01:20:03