Smurf Stuff discussed in the prev section
// Pure Virtual functions and Abstract Classes and Smurfs
class SkilledSmurf : public Smurf {
public:
SkilledSmurf ();
virtual void DoSkill () = 0;
};
class HeftySmurf : public SkilledSmurf {
public:
HeftySmurf ();
void DoSkill ();
};
void BrainySmurf : public SkilledSmurf {
public:
BrainySmurf ();
virtual void BeSmart () = 0;
virtual void Lecture ();
};
void BrainySmurf::Lecture () {
cout << "Papa says: 2 + 2 = 5" << endl;
}
// What can Smurfs do ? What do the following do ? Are there errors ?
Smurf asmurf;
HeftySmurf hsmurf;
hsmurf.DoSkill ();
HeftySmurf *hptr = new HeftySmurf;
htpr->DoSkill ();
SkilledSmurf *sptr = new HeftySmurf;
aptr->DoSkill ();
asmurf.DoSkill ();
BrainySmurf bsmurf;
// Today's new eclasses: Smurfy new classes
1) Complete the implementations of 3 classes SkilledSmurf, HeftySmurf,
BrainySmurf.
2) Make a new class such that the following works:
BrainySmurf *ptr = new YourNewClass;
ptr->Lecture ();
ptr->BeSmart ();
ptr->DoSkill ();
ptr->Sing ();
3) Write a function which, when given a Smurf, will make it perform the
correct DoSkill for the dynamic type of that object.
4) Now, write a function that given an array of Smurfs, will cause each of the
Smurfs in the array to perform it's DoSkill
5) Be Smurfy;
SOLUTIONS COMING UP NEXT WEEK