Is there a standard #include convention for C++?

前端 未结 8 1800
隐瞒了意图╮
隐瞒了意图╮ 2021-01-01 16:49

This is a rather basic question, but it\'s one that\'s bugged me for awhile.

My project has a bunch of .cpp (Implementation) and .hpp (Definition) files.

I f

8条回答
  •  借酒劲吻你
    2021-01-01 17:44

    I always use the principle of least coupling. I only include a file if the current file actually needs it; if I can get away with a forward declaration instead of a full definition, I'll use that instead. My .cpp files always have a pile of #includes at the top.

    Bar.h:

    class Foo;
    
    class Bar
    {
        Foo * m_foo;
    };
    

    Bar.cpp:

    #include "Foo.h"
    #include "Bar.h"
    

提交回复
热议问题