Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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