reincluding header in implementation

后端 未结 3 1898
遇见更好的自我
遇见更好的自我 2021-01-05 11:16

suppose I have a header foo.h like this:

#ifndef FOO_H
#define FOO_H
#include 
#include \"non_standard_class.h\"

std::string foo(         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-05 11:29

    Personally I follow the (questionable) minimal inclusion practice: I only include what's needed for compilation to work.

    People telling to get a better compiler / machine quite make me laugh, in a way, the project I am working on daily is compiled in about 8 minutes (from scratch) on a quad-core (was about 1 hour before I scrapped down dependencies) and I find it too damn long. I certainly don't want any change to cause the whole thing to recompile, and therefore I am wary of any include.

    During development, I always feel like compilation time is wasted time. A bit might allow a break sure, but when you want to test something now, it's only frustrating to wait for the damn thing to finally be ready (especially if it just blows in your hand when testing and you realize you'll have to modify it again and re-compile again).

    Including things twice seems like a good way to forget to remove the include from the source when it's no longer need by the header (hurray for forward declaration), I don't see the point.

提交回复
热议问题