C++类模板的特化分为两种,一种是全特化,另一种是偏特化。
下面这个例子就是全特化
#include<iostream>
using namespace std;
template<class T>
class SeqList
{
public:
SeqList();
~SeqList();
private:
int _size;
int _capacity;
T* _data;
};
template<class T>
SeqList<T>::SeqList()
:_size(0), _capacity(0), _data(new T[_capacity])
{
cout << "SeqList<T>" << endl;
}
template<class T>
SeqList<T>::~SeqList()
{
delete[] _data;
}
template<>
class SeqList<int>
{
public:
SeqList(int capacity);
~SeqList();
private:
int _size;
int _capacity;