class X
{
protected:
void protectedFunction() { cout << "I am protected" ; }
};
class Y : public X
{
public:
using X::protectedFunction;
};
int main()
{
Y y1;
y1.protectedFunction();
}
This way I am able to expose one of the functions of the base class.
- Doesn’t this violate the encapsulation principle?
- Is there a specific reason as to why this is in standard?
- Is there any uses of this, or is it going to be changed in the new standard?
- Are there any open issues related to this in the standard?
Yes it does and that’s why protected has received a fair share of criticism.
Bjarne Stroustrup, the creator of C++, regrets this in his excellent book The Design and Evolution of C++: