Reputation: 13
I have a core code that I don't want to hack. There's like 30 objects in c++ that are updated with help of GitHub.
My software takes this code and implements a lot of things and change others. What I need to do is to somehow use a class and method if this code is available in another namespace or folder or use the original if not.
Also, I can't change the core (with exception of main).
I aim to have an organized code struct with relativity maintainability.
Example:
#include <iostream>
namespace core {
class foo1 {
public:
static void fun1(){
std::cout << "fun1 from foo1 from core" << std::endl;
}
static void fun2(){
std::cout << "fun2 from foo1 from core" << std::endl;
}
};
class foo2 {
public:
static void fun3(){
std::cout << "fun3 from foo2 from core" << std::endl;
core::foo1::fun1();
}
};
};
namespace hack {
class foo1 {
public:
static void fun1(){
std::cout << "fun1 from foo1 from hack" << std::endl;
}
};
class foo2 {
public:
static void fun3(){
std::cout << "fun3 from foo2 from hack" << std::endl;
}
};
};
int main(void){
XXX::foo2::fun3();
XXX::foo1::fun2();
}
In this example, I'd like to the linker dynamically find if there's the method "fun3" in the namespace "hack" and class "foo2", if true, use it, if not, try in namespace "core". Same for "fun2" in "foo1".
Therefore, the output should be:
fun3 from foo2 from hack
fun2 from foo1 from core
Remember, I don't want to hack core (maybe just main function), all of this is outside the code. It's some kind of interception. I don't know what to search for. All the terms I've tried didn't get any results. I don't know if polymorphism could be used either. Another problem it's that the compiler could not find some method in the file it could find some error (for the hacked class in the namespace hack). I know that in PHP there's a way to do that.
Upvotes: 0
Views: 44