How can I avoid including class implementation files?

前端 未结 7 844
轮回少年
轮回少年 2020-11-29 11:45

Instead of doing

#include \"MyClass.cpp\"

I would like to do

#include \"MyClass.h\"

I\'ve read online tha

7条回答
  •  暖寄归人
    2020-11-29 12:24

    In addition to hiding implementation details in cpp files (check other replies), you can additionally hide structure details by class forward declaration.

    class FooPrivate;  
    
    class Foo  
    {  
      public:  
      // public stuff goes here  
      private:  
      FooPrivate *foo_private;  
    };
    

    The expression class FooPrivate says that FooPrivate is completely defined somewhere else (preferably in the same file where Foo's implementation resides, before Foo's stuff comes. This way you make sure that implementation details of Foo(Private) aren't exposed via the header file.

提交回复
热议问题