troubleshooting Question

Convert a reverse_iterator to const_reverse_iterator

Avatar of anasagasti
anasagasti asked on
C++Editors IDEs
5 Comments1 Solution954 ViewsLast Modified:
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_iterator 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_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_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.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros