Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overloading type from parent namespace

This seems to compile correctly:

namespace A {
    template<typename T>
    struct S {};

    namespace B {
        using S = S<int>;
    }
}

int main() {
    using namespace A::B;
    S s;
}

Even though at the line using S = S<int>, the first S refers to A::B::S, whereas the second S refers to the template A::S.

Is this standard C++?

like image 522
tmlen Avatar asked Feb 25 '20 09:02

tmlen


1 Answers

The scope of S begins at its point of declaration, and for a using declaration it is after the type-id to which the alias refers (S<int>).

So inside of the declaration, the scope of the new S has not started yet, and S still refers to A::S.

According to https://en.cppreference.com/w/cpp/language/scope#Point_of_declaration.

like image 129
tmlen Avatar answered Oct 07 '22 00:10

tmlen