简体   繁体   English

在编译时阻止标题包含在某些文件中?

[英]Prevent header from being included in some files, in compilation time?

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. 另外,我有一个接口I1(在一些其他文件中定义),从中派生出各种实现。 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? 我可以使用一些聪明的模板/预处理技巧吗?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM