DOC PREVIEW
FSU COP 3330 - Polymorphism

This preview shows page 1-2-3 out of 8 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Polymorphism Fall 2008What is PolymorphismPolymorphismFunction OverridingSlide 5Slide 6Slide 7DLList.h ExamplePolymorphismFall 2008 Dr. David A. [email protected] is Polymorphism Essentially, it is a programming feature that allows us to take data values of different types and use what would appear to be the same interface. Example: Printing out an integer and a floating point number internally requires different functions. But to a C++ programmer they both appear to be the same. int a=1;double b=0.0; cout << a << endl;cout << b << endl;Polymorphism•Note that we can already have multiple member functions with the same name but difference parameters (signature). Take as an example the following constructors: DLLink::DLLink();DLLink::DLLink(int CRN);DLLink::DLLink(int CRN, string t);•The compiler knows how to differentiate between the three because of the different parameter types and number of parameters.Function Overriding // Suppose we have the // following base classclass Student{ public: void GradeReport();… ( Other stuff)};// Take the following derived// classes: class Grad : public Student{ public: void GradeReport(); };class Undergrad: public Student{ public GradeReport(); };// Look at the definitions // and subsequent calls to// GradeReportStudent S; Grad G; Undergrad U; S.GradeReport(); // Calls // Student // Version. G.GradeReport(); // Calls // Grad // VersionU.GradeReport(); // Calls // Undergrad // Version// Here is a way to override // The override. // This has the Undergraduate// member function calling the// base class version. class Grad : public Student{ public: void GradeReport(); };class Undergrad: public Student{ Student::GradeReport(); };DLList.h Exampleifndef DLLIST_H#define DLLIST_H#include <string>using namespace std;class Node {public: int CourseRefNum; string Title; string CourseNumber; int Section; string Instructor; int SeatsTotal; int SeatsAvail; string Building; string Room; Node * Prev; Node * Next; }; class DLList: public Node


View Full Document

FSU COP 3330 - Polymorphism

Download Polymorphism
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Polymorphism and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Polymorphism 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?