1

I have a problem with the folowing code :

struct A
{
    A(int i) {};
};

namespace Foo
{
using Alias = A;
}

struct B : Foo::Alias
{
    B();
};

B::B() : Alias(5)
{}

int main()
{
    return 0;
}

It doesn't compile because in the B constructor, I don't precise the scope of Alias.

Why ?

Thanks.

TonySalimi
  • 8,257
  • 4
  • 33
  • 62
Oodini
  • 829
  • 1
  • 6
  • 16

1 Answers1

0

From cppreference on the namespace page:

inline(optional) namespace attr(optional) identifier { namespace-body }

The namespace-body defines a namespace scope, which affects name lookup. All names introduced by the declarations that appear within namespace-body (including nested namespace definitions) become members of the namespace identifier, whether this namespace definition is the original namespace definition (which introduced identifier), or an extension namespace definition (which "reopened" the already defined namespace)

So, based on what the standard has mentioned, whatever is defined inside the namespace as namespace-body, is considered at the scope of that namespace and qualified name lookup applies while referring to anything inside the namespace.

TonySalimi
  • 8,257
  • 4
  • 33
  • 62