I found strange behavior when using a reference variable.
Here is the implementation of the classes:
class Base { public: virtual void Method() = 0; }; class DerivedA : public Base { public: virtual void Method() {} } class DerivedB : public Base { public: virtual void Method() {} }
Here is an example of code that has weird behavior:
void main(int argc, char *argv[]) { DerivedA a; DerivedB b; Base &base = a; base.Method();
In conclusion, it seems that the virtual table pointer function is βlinkedβ to the reference variable only when initializing reference variables. If I reassign the reference variable, vfpt will not change.
What's going on here?
source share