Search code examples
c++using

Use of using X::func in public


Recently I came across a code shown below. What does it achieve? How can we bring a private part of an object to public space? I am aware of the usage of using BX::f , if the derived class hides the base class function.

 class BX { 
 public: 
 void f(int); 
 void f(char const*); 
 void g(); 
}; 
class DX : private BX { 
 public: 
 using BX::f; 
};

Solution

  • It makes the f functions public members of DX but without making anything else from BX accessible.

    The functions are already public members of BX so this does not break encapsulation.