templates/abc/prog.cpp - Full and partial specializations of a class template A. | Lecture 5 - slide 40 : 40 Program 1 |
#include <iostream> #include <string> template <typename S, typename T> class A{ // The primary template class // ... }; template<> class A <int, std::string> { // Complete specialization to S = int, T = string // }; template<typename S, typename T> class A <S*, T*> { // Partial Specialization to pointers // }; template<typename T> class A <T, T> { // Partial specialization: T and S are the same types // }; int main(){ A<double,bool> a1; // Use of A<S,T> A<int,std::string> a2; // Use of A<int,string> A<double*,std::string*> a3; // Use of A<T*,S*> A<double,double> a4; // Use of A<T,T> }