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

Info iconThis preview shows pages 1–9. 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
Background image of page 1

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

View Full DocumentRight Arrow Icon
: 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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
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 6
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 ± Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 7 / 25
Background image of page 7

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

View Full DocumentRight Arrow Icon
Polymorphism : Recapping I Some terminiology: Abstract base class. Cannot be instantiated because it contains pure virtual functions.
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 25

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

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

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