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

前端 未结 17 1879
终归单人心
终归单人心 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 16:10

    You're going outside of the design scope of the language. While you may have some benefits, it's going to eventually bite you in the butt.

    C++ is designed for h files having declarations, and cpp files having implementations. Compilers are built around this design.

    Yes, people debate whether that's a good architecture, but it's the design. It's better to spend your time on your problem than reinventing new ways to design C++ file architecture.

提交回复
热议问题