Feb 25 2006 sat ::reading the introduce of the stl

1:C++构造函数的初始化方法:
  • 缺省构造函数(default constructor)
  • shape() : x_pos(0), y_pos(0), color(1) {}
  • 拷贝构造函数(copy constructor)
  • shape(int x, int y, int c = 1) : x_pos(x), y_pos(y), color(c) {}
  • shape(const shape& s) : x_pos(s.x_pos), y_pos(s.y_pos), color(s.color) {}

2: 数对象(Function Objects)

在使用STL时,经常需要把函数对象作为算法的输入参数,或着实例化一个容器(container)时的输入参数。所谓函数对象(function object)是定义了函数调用操作符(funiton-call operator,即operator())的对象。请看下面的例子:

class less
{
public:
More(int v) : val(v) {}
int operator()(int v)
{
    return v > val;
}
private:
int val;
}
声明一个
Mess 对象:
 More more_than_5(5);

一个最简单的模板 swap

函数模板 :
void swap(int& a, int& b)
{
int tmp = a;
a = b;
b = tmp;
}

   ||
 /    /

template <class T>
void swap(T& a, T& b)
{
T tmp = a;
a = b;
b = tmp
}

容器(Container)

TL中有顺序容器(Sequence Container)和关联容器(Associative Container)

顺序容器组织成对象的有限线性集合,所有对象都是同一类型。STL中三种基本顺序容器是:向量(Vector)、线性表(List)、双向队列(Deque)


顺序容器(Sequence Container)

向量(Vector)


双向队列(Deque)


线性表(List)

关联容器(Associative Container)

集合(Set)


多集合(MultiSet)


映射(Map)


多映射(MultiSet)


 

 

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值