// LateBinding - in late binding the decision as to // which of two overloaded functions // to call is made at run time #include #include class Student { public: virtual double calcTuition() { return 0; } }; class GraduateStudent : public Student { public: virtual double calcTuition() { return 1; } }; double fn(Student& fs) { // since calcTuition() is declared virtual this // call uses the run time type of fs to resolve // the call return fs.calcTuition(); } int main(int nArgc, char* pszArgs[]) { // the following expression calls // fn() with a Student object Student s; cout << "The value of s.calcTuition when\n" << "called virtually through fn() is " << fn(s) << "\n\n"; // the following expression calls // fn() with a GraduateStudent object GraduateStudent gs; cout << "The value of gs.calcTuition when\n" << "called virtually through fn() is " << fn(gs) << "\n\n"; return 0; }