I am writing a library which gets preloaded using LD_PRELOAD to different versions of other code (which I don't want/cannot change). In a former version, a class method A::foo() of class A exists and in a later version, it doesn't.
For global (C-like) function, I am using the attribute((weak)) mechanism to check whether a function is actually defined when running the code:
void foo() __attribute__(weak));
if (foo) { foo(); }
That doesn't seem to work for class members.
The compile-time error is:
no ‘int somenamespace::SomeClass::someFunction()’ member function declared in class ‘somenamespace::SomeClass’
int somenamespace::SomeClass::someFunction() __attribute__((weak));
^
...
./file.cpp: In member function ‘virtual void somenamespace::OtherClass::initialize()’:
./file.cpp:397:32: error: ‘class somenamespace::SomeClass’ has no member named ‘someFunction’
num = theinstance.someFunction();
Is there a way to check for existance which does not rely on the definition being known at compile time?
I cannot use templates as in Is it possible to write a template to check for a function's existence? because I templates are evaluated during compilation.
Also, How to Check if the function exists in C/C++ was of no help.