{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

: 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

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

View Full Document
: 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 Previously, we pointed out that we couldn’t write a Newton-Raphson function. We could as soon as we introduced classes, but it still wasn’t general enough. 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

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

View Full Document
Polymorphism : 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 { Derived “is a ” Base. Base *p = new Derived(); 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

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

View Full Document
Polymorphism : virtual functions Functions in a base class can be declared virtual. Derived classes can override these functions. Base *p = new Derived(); p->some virtual f(); Calls the Derived class’s function. This is called polymorphism. c Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 6 / 25
Polymorphism : Example Diving right into an example. Let’s think for a second about functions of the form f ( x ). 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

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

View Full Document
Polymorphism : Recapping Some terminiology: Abstract base class. Cannot be instantiated because it contains pure virtual functions.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}