Hiding a C++ class in a header without using the unnamed namespace

后端 未结 7 1759
走了就别回头了
走了就别回头了 2020-12-19 12:50

I am writing a C++ header in which I define a

class A {
   // ...
};

that I would like to hide from the outside world (because it may chang

7条回答
  •  一生所求
    2020-12-19 13:14

    Document that this class is not part of the public API and should not be used.

    In C++ you have to trusted programs that link with your library code because you have little other choice. C++ has limited "access control" features many of which can be bypassed or abused so you're better of treating your API clients with respect and building trust.

    If you design your API to be easy to use correctly and hard to use unintentionally incorrectly then you will be helping your clients and it is hardly your fault if your clients abuse your interface.

提交回复
热议问题