#include #include using std::cout; using std::endl; timeval end; timeval beg; class shape { public: virtual ~shape() {} }; class square : public shape { int val; public: square() { val = 4; } void print() { cout << "Hi I am a square with " << val << " sides" << endl; } }; class triangle : public shape { int val; public: triangle() { val = 3; } void print() { cout << "Hi I am a triangle " << val << " sides" << endl; } }; int main(int argc, char** argv) { square* sqr = new square; shape* shp = sqr; gettimeofday(&beg, NULL); // average of 3 micro seconds on my turion64 single core laptop triangle* t1 = static_cast(shp); gettimeofday(&end, NULL); t1->print(); cout << (end.tv_sec - beg.tv_sec) * 1000000 + (end.tv_usec - beg.tv_usec) << " micro seconds for cast" << endl; return 0; }