侯捷C++ 模板template
课程中模板模板参数的举例
template<typename T,
template <typename T>
class Container
>
class XCls
{
private:
Container<T> c;
public:
XCls()
{
for(long i=0; i< 100; ++i)
c.insert(c.end(), T());
}
};
template<typename T>
using Lst = list<T, allocator<T>>;
XCls<string,Lst> X;
模板偏特化的举例
(个数)//注意,模板的特化不是指定初值,而是指定对某类模板的特殊实现
template<typename T, typename Alloc=......>
class vector
{
...
};
template<typename Alloc=......>
class vector<bool, Alloc>
{
...
};
(范围)
template <typename T>
class C//任意
{
...
};
template <typename T>
class C<T*>//指针
//也可以使用不同typename
//template <typename U>
//class C<U*>//指针
{
...
};