CS ¡162 ¡ Intro ¡to ¡Programming ¡II ¡
Polymorphism ¡II ¡
1 ¡
CS 162 Intro to Programming II Polymorphism II 1 - - PowerPoint PPT Presentation
CS 162 Intro to Programming II Polymorphism II 1 Virtual Func:ons Which is which, for changing the behavior of inherited func:ons?
1 ¡
2 ¡
3 ¡
4 ¡
5 ¡
6 ¡
7 ¡
8 ¡
9 ¡
10 ¡
11 ¡
12 ¡
13 ¡
void Bunny::print() const { std::cout << "Name: " << name << std::endl; } ¡/* In MutantBunny.cpp*/ void MutantBunny::print() const { Bunny::print(); std::cout << "Bunnies eaten: " << std::endl; for( int i = 0; i < namesOfBunniesEaten->size();i++ ) { std::cout << "\t" << (*namesOfBunniesEaten)[i] << std::endl; } }
14 ¡
15 ¡
MutantBunny *mb = new MutantBunny("Fluffy"); mb->addNameOfBunnyEaten("Bugs"); Bunny *b = mb; b->print();
16 ¡
17 ¡
18 ¡