l14_6up - : : CSci 1113 C/C+ for Scientists and Engineers...

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

View Full Document Right Arrow Icon
: CSci 1113 C/C++ for Scientists and Engineers Section 010 - evening class Object Oriented Programming in C++. Inheritance, ad-hoc polymorphism Prof. Eric Van Wyk and Ted Kaminski Spring 2010 c ± Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 1 / 25 : I Lab midterm exam. Check that your score is in GRIT. We have two exams with no names - so two people have zeros that deserve better. c ± Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 2 / 25 Polymorphism : Motivating example I Previously, we pointed out that we couldn’t write a Newton-Raphson function. I We could as soon as we introduced classes, but it still wasn’t general enough. I Today, we’ll introduce polymorphism which solves this problem. c ± Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 3 / 25 Polymorphism : I First: a teaser. c ± Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 4 / 25 Polymorphism : Child classes class Derived : public Base { I Derived “is a ” Base. I Base *p = new Derived(); I What’s the point of that? c ± Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 5 / 25 Polymorphism : virtual functions I Functions in a base class can be declared virtual. I Derived classes can override these functions. I Base *p = new Derived(); p->some virtual f(); I Calls the Derived class’s function. I This is called polymorphism. c ± Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 6 / 25
Background image of page 1

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

View Full DocumentRight Arrow Icon
Polymorphism : Example I Diving right into an example. I Let’s think for a second about functions of the form f ( x ). I Function.h and friends will be posted on the website. c
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

l14_6up - : : CSci 1113 C/C+ for Scientists and Engineers...

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

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