c++ using declaration, scope and access control

后端 未结 3 1436
深忆病人
深忆病人 2020-12-09 19:55

Typically the \'using\' declaration is used to bring into scope some member functions of base classes that would otherwise be hidden. From that point of view it is only a me

3条回答
  •  醉梦人生
    2020-12-09 20:13

    While the using declaration you showed does provide a mechanism to change access level (but only down), that is not the primary use of it in such a context. A using context there is primarily intended to allow access to functions that would otherwise be shadowed from the base class due to the language mechanics. E.g.

    class A {
    public:
       void A();
       void B();
    };
    
    class B {
    public:
       using A::B;
       void B(int); //This would shadow A::B if not for a using declaration
    };
    

提交回复
热议问题