Learning objectives:
This lab does not have any distribution code.
Vtables. Consider the following C++ code:
struct A { void foo() { cout << "A::foo()" << endl; } virtual void bar() { cout << "A::bar()" << endl; } }; struct B : A { virtual void foo() { cout << "B::foo()" << endl; } void bar() { cout << "B::bar()" << endl; } }; int main() { A *aptr = new B; aptr->foo(); aptr->bar(); }
This code prints the following when run:
A::foo() B::bar()
Vtable and object layout. Consider the following C++ code:
#include <iostream> using std::cout; using std::endl; struct A { int x; virtual void spam() { cout << "A::spam()" << endl; } virtual void eggs() { cout << "A::eggs()" << endl; } }; struct B : A { int x; virtual void eggs() { cout << "B::eggs()" << endl; } }; struct C : B { int z; virtual void spam() { cout << "C::spam()" << endl; } };