Is it a good idea to put all project headers into

2020-07-17 04:34发布

I talked to my instructor the other day and asked him this question. He told me that I could go for smaller projects, but I'm starting a chess program and I was wondering what Stack Overflow thinks about this issue. Should I include all headers into one file, or separate them?

标签: c++ header
7条回答
2楼-- · 2020-07-17 05:02

I just want to add that, yes this is normally a bad idea, but it can be useful on occasion. Never for entire projects though.

For example, I recently wrote a utility to perform a stack dump on windows. There were 4 common headers I was going to include, so I made (in a detail folder, a convention I stole form boost use) a windows.hpp, which included those four. The implementations could then use that header to easily get the necessary functions.

While it might not carry the same weight as a mega-includes-480-headers header, it was a grouping of a handful of common headers, and it was quite helpful. the key thing here is it was a small collection of related headers, used in a portion of the code.

查看更多
登录 后发表回答