cs246-s11-001-july7

cs246-s11-001-july7 - CS 246 (Spring 2011) Section 1...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 246 (Spring 2011) – Section 1 Thursday 7 July Inheritance and Templates
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS 246 (Spring 2011) - Section 001 - Thursday 7 July 2 Today's Agenda Brief comments about the assignments (at the break) Finish inheritance Start templates Submit your feedback
Background image of page 2
CS 246 (Spring 2011) - Section 001 - Thursday 7 July 3 Ideas from last day Example from the end of last class class Animal { protected: string name; int age; public: Animal(string n, int a ) { name = n; age = a; } }; class Cat : public Animal { public: Cat(string n, int a ) : Animal(n, a ) {} void makeNoise() { cout << “meow” << endl; };
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS 246 (Spring 2011) - Section 001 - Thursday 7 July 4 Example Let's say we add the following private member function in the Cat class: int getAge() { // age in cat years if (age==1) { return 15; } else if (age==2) { return 25; } else { return 25 + (age-2)*4; } } } What happens? Animal *a = new Cat(“Chester”, 2); a->getAge();
Background image of page 4
CS 246 (Spring 2011) - Section 001 - Thursday 7 July 5 2.24.10 Abstract Class How do we fix this problem? Depends on our
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 12

cs246-s11-001-july7 - CS 246 (Spring 2011) Section 1...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online