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

后端 未结 6 2165
傲寒
傲寒 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:22

    You should use explicit #includes to have a non destructive workflow. Let's say that MyClass is used in 50 different source files. They don't include vector. Suddenly, you have to change std::vector in MyClass.h for some other container. Then all the 50 source files will either need to include vector or you will need to leave it in MyClass.h. This would be redundant and it could increase application size, compilation time and even run time (static variable initialization) unnecessarily.

提交回复
热议问题