1

This link talks about allowing more restrictive access to a derived class method.

Q. What is the reason for allowing this in C++?

Languages such as Java & C# don't allow it. Is it useful in some cases? If so please help me understand.

Community
  • 1
  • 1
Destructor
  • 14,123
  • 11
  • 61
  • 126

1 Answers1

4

It has more to do with it never being disallowed. And now it's too late: too much code would break. Do remember that C++ is a considerably older language than either Java or C#.

But the C++ philosophy inspires you to ask "why disallow it?". It could even be useful: some folk exploit it and make overridden methods private. The amount of documentation you should attach to a private method can be significantly less than a public method. This means you don't repeat yourself and are compelled to rely on the public / protected method in a base class for comments.

Bathsheba
  • 231,907
  • 34
  • 361
  • 483