anasagasti
asked on
Convert a reverse_iterator to const_reverse_iterator
Using VC++6.0
Is it possible to convert a reverse_iterator to a const_reverse_iterator? I don't know if it's again a problem in this version of the STL
The following code in my case doesn't work:
main()
{
typedef set<int> Sint;
Sint s1;
s1.insert(s1.end(), 1);
s1.insert(s1.end(), 2);
Sint::reverse_iterator rit = s1.rbegin();
Sint::const_reverse_iterat or crit(rit);
cout << *crit << endl;
return 0;
}
I obtain this error
Thanks
error C2664: '__thiscall std::reverse_bidirectional _iterator< class std::_Tree<int,int,struct std::set<int,struct std::less<int>,class std::allocator<int> >::_Kfn,struct std::less<int>,class std::allocator<int>
>::const_iterator,int,int const &,int const *,int>::std::reverse_bidir ectional_i terator<cl ass std::_Tree<int,int,struct std::set<int,struct std::less<int>,class std::allocator<int> >::_Kfn,struct std::less<int>,class std::allocator<int> >::const_it
erator,int,int const &,int const *,int>(class std::_Tree<int,int,struct std::set<int,struct std::less<int>,class std::allocator<int> >::_Kfn,struct std::less<int>,class std::allocator<int> >::const_iterator)' : cannot convert parameter 1 from 'class
std::reverse_bidirectional _iterator< class std::_Tree<int,int,struct std::set<int,struct std::less<int>,class std::allocator<int> >::_Kfn,struct std::less<int>,class std::allocator<int> >::iterator,int,int &,int *,int>' to 'class std::_Tree<int,int,
struct std::set<int,struct std::less<int>,class std::allocator<int> >::_Kfn,struct std::less<int>,class std::allocator<int> >::const_iterator'
No constructor could take the source type, or constructor overload resolution was ambiguous
Error executing cl.exe.
Is it possible to convert a reverse_iterator to a const_reverse_iterator? I don't know if it's again a problem in this version of the STL
The following code in my case doesn't work:
main()
{
typedef set<int> Sint;
Sint s1;
s1.insert(s1.end(), 1);
s1.insert(s1.end(), 2);
Sint::reverse_iterator rit = s1.rbegin();
Sint::const_reverse_iterat
cout << *crit << endl;
return 0;
}
I obtain this error
Thanks
error C2664: '__thiscall std::reverse_bidirectional
>::const_iterator,int,int const &,int const *,int>::std::reverse_bidir
erator,int,int const &,int const *,int>(class std::_Tree<int,int,struct std::set<int,struct std::less<int>,class std::allocator<int> >::_Kfn,struct std::less<int>,class std::allocator<int> >::const_iterator)' : cannot convert parameter 1 from 'class
std::reverse_bidirectional
struct std::set<int,struct std::less<int>,class std::allocator<int> >::_Kfn,struct std::less<int>,class std::allocator<int> >::const_iterator'
No constructor could take the source type, or constructor overload resolution was ambiguous
Error executing cl.exe.
ASKER
It was just an example. In some context, you can have an implicit conversion from a reverse_iterator to a const_reverse_iterator. I wondered if that was possible. Apparently not with VC++6.0 and yes VC++2003. I know the example was absurd.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It compiles in 2003 but not in 6.0.
Thanks a lot for your help.
Thanks a lot for your help.
Wasn't really much, glad you thought it worth some points :-)
Sint::const_reverse_iterat
I'm trying to understand why you want to do it in the way you describe...