0

Given string foo, when I call:

auto bar = foo.begin();

There are 2 overloads of string::begin. One returns an string::iterator and the other returns a string::const_iterator. How can I know the type of bar? Is this just based on whether foo is const or not?

Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288

1 Answers1

3

Is this just based on whether foo is const or not?

Yes

auto is meant for deducing the exact type*


How to select iterator type using auto variable? indirectly agrees with this answer.

*Taken from: How do I get a const_iterator using auto?

Community
  • 1
  • 1
gsamaras
  • 71,951
  • 46
  • 188
  • 305