知识点:
1.iterator的定义
inline Triangular_iterator& Triangular_iterator::
operator++()
{ // prefix instance
++_index;
check_integrity();
return *this;
}
前置版本返回的对象的引用,目的是提高效率,此函数通俗讲就是直接加返回的就是+1完成的对象
inline Triangular_iterator Triangular_iterator::
operator++( int )
{ // postfix instance
Triangular_iterator tmp = *this;
++_index;
check_integrity();
return tmp;
}
++的后置版本返回的是一个临时的对象,(个人理解还请纠正)这个临时对象的生命周期应该是此后置++函数的上一层函数的执行时间,上层函数执行完这个临时对象就删除。函数中新建的一个Triangular_iterator 类型的tmp对象,此对象的目的就是保存+1之前的状态留给上层函数使用,即上层函数使用的是未加1的临时对象,实际的对象已经+1。
2.友元为了能通过编译,友元必须要先于对应class之前定义
3.function object 是某种class的实例对象,只是对其function call(应该就是小括号)进行行了重载这样这个对象就可以当做函数来使用了,这种方法比通过函数指针调用函数要高效。
class LessThan {
public:
LessThan( int val ) : _val( val ){}
int comp_val() const { return _val; }
void comp_val( int nval ){ _val = nval; }
bool operator()( int value ) const;
private:
int _val;
};