A using-declaration can not be repeated in function scope. Why is that?

后端 未结 1 944
礼貌的吻别
礼貌的吻别 2021-02-05 08: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
}
voi         


        
相关标签:
1条回答
  • 2021-02-05 09:47

    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.

    0 讨论(0)
提交回复
热议问题