1, read the following program, and write the results of the operation
(3) Pure virtual function
#include <iostream>using namespace Std;class base{public: virtual void who () = 0;}; Class Firstderived:public Base{public: void Who () {cout<< "F";}}; Class Secondderived:public Base{public: void Who () {cout<< "S";}}; int main () { firstderived first_obj; Secondderived second_obj; Base &bref=first_obj; Bref. Who (); Bref=second_obj; Bref. Who (); Base *bp; bp=&first_obj; Bp->who (); bp=&second_obj; Bp->who (); return 0;}
Expected operating Result: FSFS
Actual running results:
Error Analysis: Base &bref=first_obj; This sentence means bref for first_obj, and bref=second_obj; Second_obj for First_. obj assignment But there is no data member so there is no confusion. So the output fffs.
The 13th Week "C + + language Basics" program reading-polymorphism and abstract class (3)