Re: A quick question on VTBL
That isn't a question of v-tables because print is not virtual in A.
However if you want you could do this:
class IPrint // interface implements printing
{
public:
virtual void print() = 0;
virtual ~IPrint();
};
Now you can have different instances of classes that derive from IPrint and override printing (in their own way).
However your "database" can store an array of IPrint pointers (possible shared-pointers), and not have to know the exact class that they point to.
The best things come to those who rate
Re: A quick question on VTBL
If the function is virtual then you can call it via table. Here is a small program to show this.
// call virtual function without using its name
#include <iostream>
using namespace std;
class Base {
public:
virtual void Fun1() {
cout << "Base::Fun1" << endl;
}
virtual void Fun2() {
cout << "Base::Fun2" << endl;
}
};
typedef void(*Fun)();
int main() {
Base obj;
// declare function pointer
Fun pFun = NULL;
// call first virtual function
pFun = (Fun)*((int*)*(int*)((int*)&obj+0)+0);
pFun();
// call second virtual function
pFun = (Fun)*((int*)*(int*)((int*)&obj+0)+1);
pFun();
return 0;
}
Hope it helps.