Why put a class declaration and definition in two separate files in C++?

前端 未结 7 1553
野性不改
野性不改 2021-01-01 16:16

I\'m just wondering, what is the whole point of separating classes into an .h and a .cpp file? It makes it harder to edit, and if your class won\'t be compiled into a .lib o

7条回答
  •  没有蜡笔的小新
    2021-01-01 17:07

    Well, one of the benefits of having the code this way is that it reduces compile time.

    Let's say you have these files on your project:

    • a.h
    • a.cpp
    • b.cpp

    If you already have a.cpp compiled into an object file a.o, then if you include a.h in b.cpp, compilation should be quicker because parser won't have to deal with the whole declaration/definition of a.

提交回复
热议问题