C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Translation-unit-local functions that access private class fields

From: Simon Schröder <dr.simon.schroeder_at_[hidden]>
Date: Thu, 30 Apr 2026 20:56:17 +0200
> On Apr 30, 2026, at 10:49 AM, Rhidian De Wit <rhidiandewit_at_[hidden]> wrote:
>
> So, declaring a PEM in a header becomes impossible, but then how would one create PEMs for template classes? As those are just in headers and will be part of multiple TUs.

If we want to have a private member functions inside a header file we already have a solution for this. We don’t need PEMs in header files (though we wouldn’t disallow them as #include is just copy&paste).

I don’t see why we need special rules for linking PEMs. The general rules for linking template classes apply. Without templates we only have problems if we define a PEM with the same name in two separate TUs without specifying internal linkage. This is also nothing new. As long as we have one header file and one implementation file per class we will never run into this problem because there will be only one file using the private members of a class. And if we allow separate declarations of PEMs multiple TUs can reference these as long as they are only defined in a single TU with external linkage. This is exactly the same thing as with every private member function we currently have.

Received on 2026-04-30 18:56:31