Amir
Amir

Reputation: 541

How to have a file to contain all includes?

I have an age-old question. I'm developing an infrastructure code in C++ which has a lot of headers to be included in each header file. I ideally would like to have everything included in a header file and then just to include that header file. That of course creates infinite-loop problem where a header is included in a header that includes the same header.

Doing #ifndef or #pragma once is also not going to help. Is there any other clever way to achieve this?

Thanks

Upvotes: 0

Views: 69

Answers (1)

eerorika
eerorika

Reputation: 238311

That of course creates infinite-loop problem where a header is included in a header that includes the same header.

Simply exclude the "superheader" from the set of headers that the "superheader" includes. That way you don't get the problem.

That said, doing this is likely going to cause translation units including the "superheader" to include headers unnecessarily which may adversely affect compilation times. As such, I don't recommend this approach.

Upvotes: 1

Related Questions