News for hackers. Stuff that matters.
Re:How to Emulate the “super” Keyword in C++ by SeanBoocock on Wednesday December 27, 2017 @12:33AM (#16013087)
Oh I quite agree that in general having a deep inheritance hierarchy is not ideal and that many problems can better be solved with compartmentalization or other approaches. I was asking more in the context of you have a million+ line code base and want to make things less error prone/cleaner without refactoring large chunks of it.
Re:How to Emulate the “super” Keyword in C++ by sounds on Wednesday December 27, 2017 @01:27AM (#16013255)
Though this is not the only solution, a visitor pattern seems to match.

I can think of other possibilities; hopefully this sparks some good ideas for you. I'll sketch up how I think the visitor pattern could work, sorry if it's already obvious:

Base class A. Derived classes B, C, and D.

When A::Foo() is called run code from each class, in the order they are initialized.

  class A {
  protected:
    vector<function<void(int)>> visitFoo;
  public:
    void Foo(int bar) {
      for (auto fn : visitFoo) {
        fn(bar);
      }
    }
  };

  class B : public A {
  protected:
    // Do not override Foo in class B, C, or D.
    void FooB(int bar) {
    }
  public:
    B() {
      // visitor pattern
      visitFoo.emplace_back(FooB);
    }
  };
Repeat for C and D.