If we think about the behavior that we want, we need to be able to give an object a component of any given type. We also need to be able to fetch that same component later. We'll call these functions
Earlier in the chapter, we identified how we can use templates to create a function with generic types and give them real values when we need them. We'll use templates and polymorphism to create these two functions.
Attaching a component
The first function that we're going to write will be used to attach a component of a given type to the
Object class. Since we've already identified that we're going to store all components in a single generic container, this function will be a relatively simple template. ...