Assuming I have these two classes:
class Hello {
//members
public:
virtual int doit() {
return 3;
}
};
class Wow : public Hello {
//members
public:
virtual int doit() {
return 2;
}
};
int main(int argc, const char *argv[]) {
Hello *c = new Wow();
return c->doit();
}
As we all know, this code will be handled by a late binding in C++, implemented in LLVM IR by Clang like this:
; ...
%7 = bitcast %class.Wow* %5 to %class.Hello*
store %class.Hello* %7, %class.Hello** %c, align 8
%8 = load %class.Hello*, %class.Hello** %c, align 8
%9 = bitcast %class.Hello* %8 to i32 (%class.Hello*)***
%10 = load i32 (%class.Hello*)**, i32 (%class.Hello*)*** %9, align 8
%11 = getelementptr inbounds i32 (%class.Hello*)*, i32 (%class.Hello*)** %10, i64 0
%12 = load i32 (%class.Hello*)*, i32 (%class.Hello*)** %11, align 8
%13 = call i32 %12(%class.Hello* %8)
; ...
My question is, what if I wanna create a function called check
for example in another namespace like this:
namespace somewhereelse {
void check(Hello *c) {
// Do something
}
void check(Wow *c) {
// Do something else
}
}
Can a sort of late binding be applied to different function overloads?