#include #include using std::string; using std::cout; using std::endl; template class holder { public: T item1; U item2; holder(const T& a, const U& b) : item1(a), item2(b) {} void print() { cout << "T: size= " << sizeof(T) << " value= " << item1 << endl; cout << "U: size= " << sizeof(U) << " value= " << item2 << endl; cout << endl; } }; // specialization of the member function template<> void holder::print() { cout << "2 ints: " << item1 << " and " << item2 << endl; cout << endl; } // specialization of the class template<> class holder { public: double d1; double d2; holder(const double& a, const double& b) : d1(a), d2(b) { d1 *= 10; d2 *= 10; } void print() { cout << "2 doubles: " << d1 << " and " << d2 << endl; cout << endl; } }; // partial specialization where the types are pointers template class holder { public: T* item1; U* item2; holder(const T& a, const U& b) { item1 = new T(a); item2 = new U(b); } ~holder() { delete item1; delete item2; } void print() { cout << "T* size= " << sizeof(item1) << " value= " << *item1 << endl; cout << "U* size= " << sizeof(item2) << " value= " << *item2 << endl; cout << endl; } }; // partial specialization of the class, where first template parameter is char template class holder { public: char c1; U item2; holder(const char& a, const U& b) : c1(a), item2(b) { } void print() { cout << c1 << c1 << c1 << " and val " << item2 << endl; cout << endl; } }; int main(int argc, char** argv) { cout << "holder h(3, '2');" << endl; holder h(3, '2'); h.print(); cout << "holder h(3, '2');" << endl; holder hpoint(3, '2'); hpoint.print(); cout << "holder hi(3, 2);" << endl; holder hi(3, 2); hi.print(); cout << "holder hd(3, 2);" << endl; holder hd(3, 2); hd.print(); cout << "holder hp('3', 2);" << endl; holder hp('3', 2); hp.print(); return 0; }