A using-declaration can not be repeated in functio

2019-03-14 17:43发布

In [namespace.udecl]/10 you have the following example:

namespace A {
    int i;
}
namespace A1 {
    using A::i;
    using A::i; // OK: double declaration
}
void f() {
    using A::i;
    using A::i; // error: double declaration
}

This snippet compiles in clang.

1条回答
等我变得足够好
2楼-- · 2019-03-14 18:37

The first is a declaration inside a namespace, and the multiple using statements could happen frequently using #includes. The second is inside a definition of a function, and you would never do that unless you made a mistake. You can't define the same symbol twice either, for example, but you can declare several times.

The using statement is also more than just a declaration. It is a bit stronger, as it imports a function from one namespace to another. For example, it can pull a protected base class member function into a derived class, making it public. It's almost a definition by linkage.

查看更多
登录 后发表回答