C++ Logo

std-discussion

Advanced search

Re: Access level for defaulted comparison operators

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Wed, 24 Nov 2021 13:34:50 -0500
On Wed, Nov 24, 2021 at 10:21 AM Richard Hazlewood via Std-Discussion
<std-discussion_at_[hidden]> wrote:
>
> Hi,
>
> I was recently going through a refactoring exercise to make use of
> default comparison operators.
>
> For some hierarchical classes I was concerned about the slicing problem,
> so thought no problem I'll just make the base operator protected.
>
> However, this fails to compile (with gcc 10 & 11, -std=c++20). It
> appears that the base operator is inaccessible.

... yes. That's what you *asked* for when you made it protected. You
stated that code outside of the derived hierarchy of classes cannot
call it.

This includes `main`.

Received on 2021-11-24 12:35:08