Project

General

Profile

Actions

Improvements #14752

open
MS

Avoid default arguments in signature of virtual functions

Improvements #14752: Avoid default arguments in signature of virtual functions

Added by Michael Seibt 30 days ago.

Status:
New
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
08/17/2026
Due date:
% Done:

0%

Estimated time:

Description

Affected: several member functions of all Wt versions (up to Wt 4.14.1 as of today)

If one needs to override void setHidden(bool hidden, const WAnimation& animation = WAnimation()) f.i.,
the compiler will not apply the default argument for widget->setHidden(true) if widget is a pointer to the specialized class.
Duplicating the default argument(s) in the override is error-prone because it can result in API Divergence.
The usual recommendation is to provide the default argument(s) by means of a non-virtual overload, i.e.

virtual void setHidden(bool hidden, const WAnimation &animation) = 0;
void setHidden(bool hidden) { setHidden(hidden, WAnimation{}); }

The override in e.g. WDialog would look like:

virtual void setHidden(bool hidden, const WAnimation& animation) override;
using WPopupWidget::setHidden;

I could create a pull request which addresses this for

  • WAbstractItemModel::index
  • WWidget::positionAt
  • WWidget::setHidden

Are you interested?

No data to display

Actions

Also available in: PDF Atom