What does the “::” mean in “::tolower”?

后端 未结 4 1456
遇见更好的自我
遇见更好的自我 2020-12-15 09:34

I\'ve seen code like this:

std::string str = \"wHatEver\";
std::transform(str.begin(), str.end(), str.begin(), ::tolower);

And I have a que

4条回答
  •  旧时难觅i
    2020-12-15 10:24

    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()
    }
    

提交回复
热议问题