C++ Logo

std-discussion

Advanced search

Re: Decouple constness for inherited interfaces

From: Lior Lahav <lahavlior_at_[hidden]>
Date: Sun, 22 Sep 2019 02:02:37 +0300
>
> the cases where the interface explicitly wants that any and all

derived classes should have no side-effects


It is currently possible in CPP. Declaring a base class interface method as
const ensures that a derived overridden method won't have side effects,
however that is in contradiction to my argument, claiming that it is not
necessary nor necessarily correct.

Occasionally that leads to reluctantly declare variables in derived classes
as mutables or use const cast.

Backward compatibility should be preserved, compiling an existing code
should result in identical results having this new 'mutable' keyword
opted-in.



On Sat, 21 Sep 2019 at 22:52, Thiago Macieira via Std-Discussion <
std-discussion_at_[hidden]> wrote:

> On Friday, 20 September 2019 20:50:56 PDT Lior Lahav via Std-Discussion
> wrote:
> > It would be logical that a pure abstract class const correctness would be
> > decoupled from an implementation and should not dictate whether derived
> > class should have side effects.
>
> Except for the cases where the interface explicitly wants that any and all
> derived classes should have no side-effects. How should one write such a
> declaration (in the base class) that guarantees this contract?
>
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> Software Architect - Intel System Software Products
>
>
>
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>

Received on 2019-09-21 18:08:16