I have the following piece of code
#include <string>
int Foo(const std::string& str){
std::string::iterator start;
start = str.begin();
return 0;
}
When i compile it with GCC 4.7.3 i receive an error.As i suspect the error pops up because i am trying to assign a
std::string::const_iterator;
to an
std::string::iterator
So changing the line
std::string::iterator start;
To
std::string::const_iterator start;
Compiles it finely.
My question is how the std::string member function begin() recognises that the object it is being called by is const and so returns a const_iterator.
Making the question more general:
Can i change or somehow overload a class member function to act differently when being called by a const object?