I've read a lot of posts and everyone says, that virtual table is per class, not per object and object only has _vtpr pointer to shared vtable. But please consider this example:
class Base
{
public:
virtual void func1(void) {}
virtual void func2(void) {}
private:
int dummy;
};
class Der1 : public Base
{
public:
virtual void func1(void) {}
private:
int dummy;
};
class Der2 : public Base
{
public:
virtual void func2(void) {}
private:
int dummy;
};
int main(void)
{
Base * obj1 = new Der1;
Base * obj2 = new Der2;
}
Does obj1 and obj2 relates to that one unique Base class vtable? I believe the answer is no, but can you please explain? And if both of these objects do relate to the same vtable, how it is determined which methods to be called? For example, obj1->func1 reference is different than obj2->func1.
UPDATE:
What operations are executed when doing Base * obj1 = new Der1;
? Can someone write a pseudo code for these actions?