lurscher lurscher - 5 months ago 59
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.



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