Pros & Cons of putting all code in Header files in C++?

前端 未结 17 1905
终归单人心
终归单人心 2020-12-02 15:48

You can structure a C++ program so that (almost) all the code resides in Header files. It essentially looks like a C# or Java program. However, you do need at least one

17条回答
  •  甜味超标
    2020-12-02 15:58

    If you are using template classes, you have to put the whole implementation in the header anyways...

    Compiling the whole project in one go (through a single base .cpp file) should allow something like "Whole Program Optimisation" or "Cross-Module Optimisation", which is only available in a few advanced compilers. This is not really possible with a standard compiler if you are precompiling all your .cpp files into object files, then linking.

提交回复
热议问题