Header file best practices for typedefs

前端 未结 5 1327
温柔的废话
温柔的废话 2020-12-13 01:51

I\'m using shared_ptr and STL extensively in a project, and this is leading to over-long, error-prone types like shared_ptr< vector< shared_ptr

5条回答
  •  悲哀的现实
    2020-12-13 02:32

    I would go with a combined approach of forward headers and a kind of common.h header that is specific to your project and just includes all the forward declaration headers and any other stuff that is common and lightweight.

    You complain about the overhead of maintaining twice the number of headers but I don’t think this should be too much of a problem: the forward headers usually only need to know a very limited number of types (one?), and sometimes not even the full type.

    You could even try auto-generating the headers using a script (this is done e.g. in SeqAn) if there are really that many headers.

提交回复
热议问题