Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Strange message from codeblocks IDE about constness of iterator

24 views
Skip to first unread message

Paul

unread,
Jun 15, 2015, 9:29:08 AM6/15/15
to
I wrote
std::vector<int> vect = {-1, 0, 1, 2, 3, -4, 4};

std::sort(vect.begin(), vect.end());


Using codeblocks, I put my cursor in the word begin and it reads const_iterator std::vector::begin()

Surely, this is wrong? vect.begin() is a non-const iterator, isn't it? Or am I missing something? Or is codeblocks just generally unreliable?

Thank you very much for your feedback.

Paul

Victor Bazarov

unread,
Jun 15, 2015, 9:34:17 AM6/15/15
to
On 6/15/2015 9:28 AM, Paul wrote:
> I wrote
> std::vector<int> vect = {-1, 0, 1, 2, 3, -4, 4};
>
> std::sort(vect.begin(), vect.end());
>
>
> Using codeblocks, I put my cursor in the word begin and it reads
> const_iterator std::vector::begin()
>
> Surely, this is wrong? vect.begin() is a non-const iterator, isn't
> it? Or am I missing something? Or is codeblocks just generally
> unreliable?

There are two versions of 'vector::begin' member function. Perhaps
codeblocks doesn't know which one to show and picks the apparently wrong
one...

V
--
I do not respond to top-posted replies, please don't ask

Paul

unread,
Jun 15, 2015, 11:46:35 AM6/15/15
to
On Monday, June 15, 2015 at 2:34:17 PM UTC+1, Victor Bazarov wrote:
> On 6/15/2015 9:28 AM, Paul wrote:
> > I wrote
> > std::vector<int> vect = {-1, 0, 1, 2, 3, -4, 4};
> >
> > std::sort(vect.begin(), vect.end());
> >
> >
> > Using codeblocks, I put my cursor in the word begin and it reads
> > const_iterator std::vector::begin()
> >
> > Surely, this is wrong? vect.begin() is a non-const iterator, isn't
> > it? Or am I missing something? Or is codeblocks just generally
> > unreliable?
>
> There are two versions of 'vector::begin' member function. Perhaps
> codeblocks doesn't know which one to show and picks the apparently wrong
> one...

Yes, if vect is a const vector, then vect.begin() is a const_iterator.

Thanks,

Paul

0 new messages