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

后端 未结 7 1719
走了就别回头了
走了就别回头了 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 12:52

    If A is an implementation detail of B, don't put its definition in the header at all. Instead:

    class B {
    
       ...
       class A * myA;
    };
    

    and then put the definition of A in the B implementation (i.e. .cpp) file.

提交回复
热议问题