Dirk Herrmann
Dirk Herrmann

Reputation: 5949

What are use-cases and/or pros and cons of having a named namespace within an unnamed namespace?

The following "named namespace within unnamed namespace" scenario is allowed (as I understand it):

namespace foo {
    namespace {
        namespace bar {
            int baz() { return 42; };
        } // bar
    } // unnamed

    int frob() {
        return bar::baz();
    }
} // foo

int froz() {
    return foo::bar::baz();
}

Is applying this considered a pattern / an anti-pattern (compared to not having the bar namespace within the unnamed namespace)? Are there any use-cases (beyond the ones below) for using such a namespace within an unnamed namespace?

The following use-cases came to my mind, which are somehow unusual and don't represent the "everyday" way of coding:

Upvotes: 0

Views: 52

Answers (0)

Related Questions