STL源码剖析——基础

六大部件

 

模板

  1. 类模板
  2. 函数模板
  3. 成员模板(类拥有本身为类模板或函数模板的成员)
  • 特化:优先选择特化版本
template<class T> struct __type_traits
{
    ...
};

template<> struct __type_traits<int>
{
    ...
};

template<> struct __type_traits<char>
{
    ...
};

....
  • 偏特化

      1. 限制部分参数类型

template<class T, class Alloc = alloc>
class vector
{
    ...
};

template<class Alloc = alloc>
class vector<bool, Alloc>
{
    ...
};

      2.限制为指针、引用、常量等

template<class T> struct iterator_traits<T*>
{
    ...
};

template<class T> struct iterator_traits<const T*>
{
    ...
};

 

重载

不能被重载的操作符:

   [1]?:

   [2].

   [3]::

   [4]sizeof

   [5].*   (引用指向类成员的指针)

不能是非成员的重载函数:

   [1]=

   [2][]

   [3]->

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值