Click on templates.cpp to get source.
#include <iostream>
#include <typeinfo>
using namespace std;
template <class T>
class A
{public: T x;
A(T y) : x(y) {}
typedef T elemT;
};// template <class T> class A
template class A<int>; // explicit template expansion
template <> // template specialization
class A<float>
{public: float z; // new data member
float x;
A<float>(float y) : z(y+10.0), x(y) {}
};// template <> class A<float>
template< template<class> class C >
// template-template parameters
class B
{public:
C<int> ci;
C<float> cf;
B(int a, float b) : ci(a), cf(b) {}
};// template <template<class> class C> class B
template<class T> // template function: overloaded <<
ostream& operator<<(ostream& out, const A<T>& a)
{out << "An A<" << typeid(T).name() << ">: x member: " << a.x;
return out; }
// link to template class specialization compiled elsewhere
extern template class A<double>;
int main(void)
{// cannot declare here: must be in namespace scope of template
// extern template class A<double>;
A<int> a1(5);
A<char> a2('A');
A<float> a3(1.5);
B<A> b(5, 1.5);
// the following declaration causes a link error
// A<double> c(3.14);
cout << "A<int> a1(5); cout << a1: " << a1 << endl;
cout << "A<char> a2('A'); cout << a2: " << a2 << endl;
cout << "A<float> a3(1.5); cout << a3: " << a3 << endl;
cout << "B<A> b(5, 1.5); cout << b.ci: " << b.ci
<< endl << " cout << b.cf: " << b.cf
<< endl << " cout << b.cf.z: " << b.cf.z << endl;
}//main