Question

I have a header file, which I can control its contents.

Additionally I have an interface I1 (defined in some other file) from which various implementations derived. I want to prohibit those implementations from including this header file. So that during compile time if the file is included the compilation will fail, otherwise it will continue as usual.

So I have header file and an interface definition (in some other file). I want to prohibit interface implementations from including the given header file, during compilation.

Any suggestions as to how I can achieve that? Is there some clever templates/preprocessing trick I can use?

Was it helpful?

Solution

In the header file:

#ifndef FOO_IMPLEMENTATION_USE_ONLY
#error This file is for inclusion in the FOO implementation only
#endif

In the files that are supposed to include it:

// Define this ONLY in the Foo implementation files
#define FOO_IMPLEMENTATION_USE_ONLY
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top