Explicit direct #include vs. Non-contractual transitive #include

后端 未结 6 2162
傲寒
傲寒 2021-02-12 12:47

Say we have this header file:

MyClass.hpp

#pragma once
#include 

class MyClass
{
public:
    MyClass(double);

    /* ... */

private:
            


        
6条回答
  •  暖寄归人
    2021-02-12 13:18

    Yes, the using file should include explicitly, as that is a dependency it needs.

    However, I wouldn't fret. If someone refactors MyClass.hpp to remove the include, the compiler will point them at every single file that was lacking the explicit include, relying on the implicit include. It is usually a no-brainer to fix this type of errors, and once the code compiles again, some of the missing explicit includes will have been fixed.

    In the end, the compiler is much more efficient at spotting missing includes than any human being.

提交回复
热议问题