C++ Logo


Advanced search

Re: Friend namespace

From: Giuseppe D'Angelo <giuseppe.dangelo_at_[hidden]>
Date: Sun, 6 Dec 2020 15:57:50 +0100
On 06/12/2020 15:29, Arthur O'Dwyer via Std-Proposals wrote:
> Physically speaking, anybody in any .cpp file can add a new member to
> any namespace.

This is true "physically", but not true logically -- usual disclaimer
that you cannot logically add stuff in namespace std, and one could
impose a similar rule about namespaces under their own control.

As another possible use case, in Qt we actually wanted to befriend a
namespace so we could define objects in such a namespace, but not expose
the relevant constructor as public (ended up not documenting the

> https://github.com/qt/qtbase/blob/dev/src/gui/painting/qcolor.h#L296
> https://github.com/qt/qtbase/blob/dev/src/gui/painting/qcolor.h#L342

My 2 c,
Giuseppe D'Angelo | giuseppe.dangelo_at_[hidden] | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

Received on 2020-12-06 08:57:57