c++ - How does the Compiler Know Whether to Call the const Overload? -
given string foo
, when call:
auto bar = foo.begin();
there 2 overloads of string::begin
. 1 returns string::iterator
, other returns string::const_iterator
. how can know type of bar
? based on whether foo
const
or not?
is based on whether
foo
const or not?
yes
auto
meant deducing exact type*
how select iterator type using auto variable? indirectly agrees answer.
*taken from: how const_iterator using auto?