This is a dumb question, going back to the basics, but I want to understand the "why" of it, so I'm posting it anyway.

Given the following code:

Code:
#include <iostream>

using namespace std;

class A
{
public:
	virtual void print() { cout<< "A.Print\n"; }
	A() { cout <<"Constructor of A.\n"; }
};

class B : public A
{
public:
	void print() { cout << "B.print\n"; }
	B() { cout <<"Constructor of B.\n"; }
};

int _tmain(int argc, _TCHAR* argv[])
{
	B *b = new B();  // ??
	reinterpret_cast<A *>(b)->print();
	return 0;
}
The output of which is:


Constructor of A.
Constructor of B.
B.print


My question is: How? How does the base-class know to call the derived class' print method? My mind is saying that the logic is "we've cast to class A" and class A knows nothing of class B, and yet the print method in class B is still being called.

Is it going to the virtual function table even though we're class A? That's the only thing I can conclude.