News for hackers. Stuff that matters.
Re:C++ Patterns: The Badge by kazinator on Tuesday June 11, 2019 @08:08PM (#20160664)
The best guard against unintended uses that hamstring the maintenance of the library is the good old opaque handle:

   typedef struct foo_struct *foo;

   foo foo_make();
   void foo_destroy(foo);
   void foo_frobnicate(foo, int how);
The client executables have no idea how big a foo object is, or what alignment requirements are, let alone what its members might be. The client executables don't control the allocation, construction, clean-up, freeing, or anything else.

The programmers who use this cannot just edit a header file to gain access to something; the don't have a header file which tells them anything. They could reverse engineer the data structure, but to thwart that, you could scramble the order of the structure members with each new release of the component, so their hack wouldn't be backward or forward compatible.

Re:C++ Patterns: The Badge by gowld on Tuesday June 11, 2019 @09:34PM (#20161023)
That doesn't solve the problem the OP solves, which is to expose a method only to a specified set of other classes.
Re:C++ Patterns: The Badge by flukus on Wednesday June 12, 2019 @03:00AM (#20162382)
It solves the problem by decoupling the public interface and necessary implementation details (object size), the register/unregister functions can be moved to an internal only header file, maybe even some file scoped functions. AFAIK this is not possible with a class declaration.

I think you could also solve this specific problem with an internal header file in c++ too (by moving register/deregister to it's own class) but this solution solves other problems like binary compatibility.