条款13: 初始化列表中成员列出的顺序和它们在类中声明的顺序相同
顽固的pascal和ada程序员会经常想念那种可以任意设定数组下标上下限的功能,即,数组下标的范围可以设为10到20,不一定要是0到10。资深的c程序员会坚持一定要从0开始计数,但想个办法来满足那些还在用begin/end的人的这个要求也很容易,这只需要定义一个自己的array类模板:
template<class t>
class array {
public:
array(int lowbound, int highbound);
...
private:
vector<t> data; // 数组数据存储在vector对象中
// 关于vector模板参见条款49
size_t size; // 数组中元素的数量
int lbound, hbound; // 下限,上限
};
template<class t>
array<t>::array(int lowbound, int highbound)
: size(highbound - lowbound + 1),
lbound(lowbound), hbound(highbound),