打造一个Iterator Class
- 这一节讲了运算符重载的相关知识,以及嵌套类型(typedef)
运算符重载
- 泛型指针类的运算,肯定不能用正常的内置类型的那种运算符。为什么?这是规定!此时我就需要运算符重载,怎么运算符重载呢?
- 运算符重载,说白了就是我重新定义原有的运算符以适合泛型指针类的运算。我可以像定义成员函数那样重新定义运算符。
- 运算符函数很像普通函数,但是运算符函数不用指定函数名。只需要在运算符前加上关键字operator即可,如:
class Triangular_iterator
{
public:
Triangular_iterator(int index):_index(index-1){
}
bool operator==(const Triagnular_iterator&)const;
bool operator!=(const Triangular_iterator&)const;
int operator*()const;
Triangular_iterator& operator++();
Triangular_iterator operator++(int