C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Derived class's function invokes base class's function

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sat, 16 Apr 2022 11:34:06 -0700
On Saturday, 16 April 2022 01:07:16 PDT Frederick Virchanza Gotham via Std-
Proposals wrote:
> I'm considering presenting an array of function pointers to
> programmers so that they have that kind of control. Here's an
> approximation of how my 'precompiler' would do it:

You're missing my point.

My point was to ask how your proposed feature would deal with the need to
conditionally call some of the base class's methods, based on results from the
prior calls. They could be:

a) stop if the function returns true (or something convertible to true)
b) stop if the function returns false (or something convertible to false)
c) stop if some other function returns true or false, as in:

  Base1::handle(event);
  if (event->handled())
      return;
  Base2::handle(event);

Then there's the question of just what the function should return if it stops
before all bases are called.

You may want to look at fold expressions and at template parameter pack
expansion for an idea of how to accomplish non-trivial expressions.

Or look at std::visit. In fact, please look at it and devise a Standard
Library solution for the problem, instead of a core language feature change.
Library updates are much easier to accept and require no overloading of
keywords.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DPG Cloud Engineering

Received on 2022-04-16 18:34:08