void list_test()
{
list<int> l;
list<int>::iterator lp;
list<int>::const_iterator cp;
list<int>::reverse_iterator rp;
list<int>::const_reverse_iterator crp;
lp = l.begin();
cp = l.begin();
rp = l.rbegin();
crp = l.rbegin();
}
在vc6 sp6 上, 上面的函数居然是编译不过的.
在于 crp = l.rbegin(); 这句
产生的错误是
error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class std::reverse_bidirectional_iterator<class std::list<int,class std::allocator<int> >::iterator,int,
int &,int *,int>' (or there is no acceptable conversion)
Error executing cl.exe.
关键是编译器认为
l.rbegin() 返回的是一个 reverse_iterator, 所以没有办法将 reverse_iterator 转换为 const_reverse_iterator, 即使在stl 的list 中定义了
const_reverse_iterator rbegin() const; 也没有用,真的是一个很奇怪的问题.