I have two libraries (third-party), and within each of these libs they have defined two classes with same name (in header files).
// Lib A, HeaderA.h
struct mycompare
{
//Some code
};
// Lib B, HeaderB.h
struct mycompare
{
//Same code
};
Please note that, in both libs, mycompare name and the implementation is same. How to use both header files same time ?
Assuming you can’t edit the headers/libraries:
#define mycompare mycompare_duplicatebefore including HeaderB.h, then#undef mycompare. This could bite you if one of the implementations later changes, and may not be possible if the header later uses the symbol itself (e.g. as a function argument, where type name-mangling would differ and prevent your calls being resolved).If you can edit the libraries, then obviously the best long-term option is to put their functionality into separate namespaces.