Why should I not include cpp files and instead use a header?

后端 未结 13 2339
天涯浪人
天涯浪人 2020-11-22 07:13

So I finished my first C++ programming assignment and received my grade. But according to the grading, I lost marks for including cpp files instead of compiling and li

13条回答
  •  醉酒成梦
    2020-11-22 07:55

    Think of cpp files as a black box and the .h files as the guides on how to use those black boxes.

    The cpp files can be compiled ahead of time. This doesn't work in you #include them, as it needs to actual "include" the code into your program each time it compiles it. If you just include the header, it can just use the header file to determine how to use the precompiled cpp file.

    Although this won't make much of a difference for your first project, if you start writing large cpp programs, people are going to hate you because compile times are going to explode.

    Also have a read of this: Header File Include Patterns

提交回复
热议问题