简体   繁体   中英

How to include header files with similar names in C++ project

I am using an external library in my C++ program. This library has a fie named "Common.h". Without knowing about this file, I also created a "Common.h" in my program. Using the compiler flag "#pragma once" in the headers I could ensure that both the files can be included in the compilation. However, I realized that when I call my "Common.h" in my program, the preprocessor wrongly includes the "Common.h" from the external library which breaks the compilation. Is there any option like "namespace" which allows me to include the correct file. I find it really difficult, as we may not (indeed need not) aware about all the files in the external library.

Usually program has several so called include paths to look for header files. It seems you have included both path to directory containing your "Common.h" file, as well as library headers directory. As for me, perfect solution seems to remove include path of library files and use explicit relative path, as:

#include "mylib/include/Common.h"

您可以简单地重命名“common.h”文件,然后包含它

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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