lurscher lurscher - 1 year ago 93
C++ Question

a way in c++ to hide a specific function

i have an inheritance

struct A : public B
, i want to hide individual functions from B, is this possible?

i know the opposite is possible using
using BMethod
in the A declaration.


Answer Source

There is an issue here: this would be a direct violation of the Liskov Substitution Principle, namely A would not act as a B any longer.

If you wish to reuse B implementation, the solution is simply to do so:

class A
  void foo() { return; }
  void bar() { return; }
  // ...

  B b;

Don't abuse inheritance, use composition instead

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download