Hi, just wrote this simple program:
and the program writes "derived" in the terminal. This is what's called run time type information (RTTI) I guess, since the print function have no way, when compiling, to know wheather ptr is really a base* or not. So how can it determine which type ptr is of in runtime? Information about which type ptr is has to be stored somewhere (hasn't it), but where?Code:#include <iostream> using namespace std; class base { public: virtual ~base() {} virtual void print() { cout << "base" << endl; } }; class derived : public base { public: void print() { cout << "derived" << endl; } }; void print(base* ptr) { ptr->print(); } int main() { base *base_ptr = dynamic_cast<base*>(new derived); print(base_ptr); system("PAUSE"); }