cs246-s11-001-july7

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

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

CS 246 (Spring 2011) – Section 1 Thursday 7 July Inheritance and Templates

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

View Full Document
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
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; };

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

View Full Document
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();
CS 246 (Spring 2011) - Section 001 - Thursday 7 July 5 2.24.10 Abstract Class How do we fix this problem? Depends on our

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 12/08/2011 for the course CS 246 taught by Professor Wormer during the Spring '08 term at Waterloo.

### Page1 / 12

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

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

View Full Document
Ask a homework question - tutors are online