lec0214-templates - Todays announcements MP3 available EC...

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

View Full Document Right Arrow Icon
Today’s announcements: MP3 available, EC due 2/18, 11:59p, due 2/25, 11:59p. DYB today, 3-5p, Siebel 2407.
Background image of page 1

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

View Full Document Right Arrow Icon
Concluding remarks for last time: Polymorphism: objects of different types can employ methods of the same name and parameterization. Inheritance provides DYNAMIC polymorphism—type dependent functions can be selected at run-time. Wikipedia: Polymorphism in OOP Next topic: “templates” are C++ implementation of static polymorphism, where type dependent functions are chosen at compile-time. animal ** farm; int farmSize = 12; farm = new animal *[farmSize]; for (int i=0; i<farmSize; i++){ if (i%3 == 0) farm[i] = new dog; if (i%3 == 1) farm[i] = new pig; if (i%3 == 2) farm[i] = new cow; } for (int i=0; i<farmSize; i++) farm[i]->speak();
Background image of page 2
int temp; temp = x; x = y; y = temp; } int main(){ int a = 1; int b = 2; char c = ‘n’; char d = ‘m’; swapInt(a,b); swapChar(c,d); cout << a << “ “ << b << endl; cout << c << “ “ << d << endl;
Background image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 10

lec0214-templates - Todays announcements MP3 available EC...

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

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