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

后端 未结 13 2498
天涯浪人
天涯浪人 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条回答
  •  萌比男神i
    2020-11-22 07:49

    It's like writing a book, you want to print out finished chapters only once

    Say you are writing a book. If you put the chapters in separate files then you only need to print out a chapter if you have changed it. Working on one chapter doesn't change any of the others.

    But including the cpp files is, from the compiler's point of view, like editing all of the chapters of the book in one file. Then if you change it you have to print all the pages of the entire book in order to get your revised chapter printed. There is no "print selected pages" option in object code generation.

    Back to software: I have Linux and Ruby src lying around. A rough measure of lines of code...

         Linux       Ruby
       100,000    100,000   core functionality (just kernel/*, ruby top level dir)
    10,000,000    200,000   everything 
    

    Any one of those four categories has a lot of code, hence the need for modularity. This kind of code base is surprisingly typical of real-world systems.

提交回复
热议问题