eecs280.discussion.week12

eecs280.discussion.week12 - EECS 280 Fall 2010 Templates...

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

View Full Document Right Arrow Icon
EECS 280 Fall 2010
Background image of page 1

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

View Full DocumentRight Arrow Icon
Templates c Pros: c Generic Programming c No duplicate code c Cons: c Doesn’t allow more than the number of templated arguments kinds of object to be stored in container c We need a mechanism to store more than one kind of object in a container!
Background image of page 2
Polymorphic containers c Pros: c Allows more than one type to be stored in a container c Cons: c No type checking done at compile time c All types have to be related to each other through some form of relationship
Background image of page 3

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

View Full DocumentRight Arrow Icon
Example – WoW Simulation c Say we wanted to perform a World of Warcraft simulation. c We have 3 different types of characters in our game: c Peasant c Soldier c Archer c With templates, we cannot have a container that stores all of these objects in one container. c However with polymorphic containers, we can do this.
Background image of page 4
Example – WoW Simulation Agent Peasant Soldier Archer
Background image of page 5

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

View Full DocumentRight Arrow Icon
Example – WoW Simulation c class Agent { … } // Agent is an ABC c class Peasant : public Agent { … } c class Soldier : public Agent { … } c class Archer : public Agent { … } c Dlist<Agent> town_citizens; Peasant * p = new Peasant; town_citizens.insertBack(p);
Background image of page 6
Understanding compiler’s concerns c What can go wrong? Dlist<Agent> town_citizens;
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/14/2010 for the course EECS 280 taught by Professor Noble during the Fall '08 term at University of Michigan.

Page1 / 19

eecs280.discussion.week12 - EECS 280 Fall 2010 Templates...

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

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