Skip to content

Instantly share code, notes, and snippets.

@xiaom
Created August 14, 2014 18:52
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save xiaom/cf1644f022bc66b3e6f9 to your computer and use it in GitHub Desktop.
C++ Notes: Prefix with Root Namespace

should we always use ::std::cout?

Use it only when you have to do. For example,

namespace X {
    double std(::std::vector<double> const& values) { … }

    void foo(::std::vector<double> const& values) {
        ::std::cout << std(values) << ::std::endl;
    }
}

In the above function, if you don't use prefix ::, the compiler will thought you refer to the function std in namespace X instead of the standard library namespace std.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment