I have a library which has a basic class which is used extensively by the particular library in question (say library_1).
namespace library_1 {
class some_class {
}
}
I have want this library to use instead another version of this class that I am defining.
namespace my_own {
class some_class {
}
}
my_own::some_class and library_1::some_class are going to have the same public interface (but different data members so they are not exactly dynamic castable). So I want to be able to compile this library replacing just this one class. This is doable.
The complication in this whole process, however, is that I have a second library (whose source code I do not have access to, call it library_2) which makes use of the first library (including accesses to some_class).
My main executable needs to access both library_2 (which is compiled against the original library) and a different version of the library_1 with this some_class replaced.
I know this is a complicated situation but what is the best way to achieve this (from a code perspective and about how to maintain this in version control)?
What you can do is to expose just the API for the part where you need to use your replace class and compile the corresponding portion into a dynamically linked library, statically resolving all symbols to the library you are meddling with. Obviously, the meddled with objects shall not escape this interface. With this, you program can effectively use two conflicting implementations of the same library although they won’t be able to shared objects. Essentially, this is how COM exposes its interface but this technique works on other platforms than Windows although I wouldn’t be come up with the needed steps in creating a shared library doing this for a UNIX system.