C++ Logo

std-proposals

Advanced search

[std-proposals] Method/member granular friendship

From: Francesco Pretto <ceztko_at_[hidden]>
Date: Mon, 11 Nov 2024 10:36:33 +0100
Hello,

I'm the maintainer of a modern C++ library that evolved from a C++98
legacy code base. Inspired by a trend which is very frequent in
Microsoft .NET base class library (where, to prevent bogus
inheritance, many classes are either final or provide inaccessible
constructors), I decided to perform an extensive API surface reduction
of the whole library. This involved making heavy use of class
friendship in C++ to the point that, within the library compilation
boundaries, some classes tend to loose proper encapsulation. In
.NET/C#, this is solved by the member "internal" visibility modifier,
which makes certain methods/fields to be accessible only within an
assembly (aka module) boundary. In C++ this could be solved by either
introducing a method/member granular friendship or (if it makes any
sense at all) having an equivalent C++ module visibility modifier. Is
there any proposal to add one of the two? Or am I missing something
already existing in the language? I'm not interested in solving the
issue through code patterns.

Regards,
Francesco

Received on 2024-11-11 09:36:45