I've seen code like this:
std::string str = "wHatEver";
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
And I have a question: what does mean ::
before tolower?
and std::tolower
not works, but ::tolower
works OK
Means that it is explicitly using the tolower
in the global namespace (which is presumably the stdc lib one).
Example:
void foo() {
// This is your global foo
}
namespace bar {
void foo() {
// This is bar's foo
}
}
using namespace bar;
void test() {
foo(); // Ambiguous - which one is it?
::foo(); // This is the global foo()
}