Class B {public: Virtual Void MF (INT P);}; void b :: mf (int p) {cout << "Member function mf in b called," << "" value of parameter is "<< P << Endl;
Class D: public b {public: void mf (double p);}; void d :: mf (double p) {cout << "Member Function Mf in D Called," << "" Value of Parameter IS "<< P << Endl;}
Void main () {b * ptr; ptr = new d; ptr-> mf (1.5);
Think What's The Output. The Output Is: Member Function MF in B Called, Value of Parameter IS 1
The Decision Process by the Complier is as Following:
1. In Main Function, a Pointer PTR IS DECLARED Whose Type Is B * .2. An Object D of Class D Is Allocated and Ptr Point To The Object D.3. As The Type of Ptr Is B *, The Program Begin To Find The Function Void MF (Double P) Defined In Class B.4. There is no function void MF (Double P) in Class B, The Program Convert Float (1.5) To int (1), and then call the function void MF INT P).