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

前端 未结 7 1530
野性不改
野性不改 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 16:49

    Because in most cases, you'll want to use the class somewhere besides the file in which you implement it. If you make the whole program in one file, you don't need the separation.

    You hardly ever want to write a C++ program all in one file.

提交回复
热议问题