Jonathan Mee
Jonathan Mee

Reputation: 38919

How does the Compiler Know Whether to Call the const Overload?

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?

Upvotes: 0

Views: 69

Answers (1)

gsamaras
gsamaras

Reputation: 73366

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?

Upvotes: 3

Related Questions