Quote:Original post by CadetUmfer
Just thought vector was using some dark corner of the language to do the impossible.
Not really, but there's still plenty to be learned from this technique. What the STL was designed to use, here and elsewhere, is what was later recognized as the
prototype pattern, whereby the nature of construction is not building a new instance from a collection of parameters (the paradigm you initially assumed was being used) but from a prototypical instance which exists not so much to
be as to
instruct new copies of itself. The first lesson, one that's definitely controversial, is that it should be possible for an object to exist without that existence having any side effects. That is, just because I construct a GameObject, doesn't mean it shows up on the screen. The second lesson is similar but distinct: Convenient copying, which goes beyond "remember the Rule of Three" to scary stuff like copy-on-write and shared pointers. The third, and most interesting lesson, comes when you generalize from the prototype pattern to
prototype-based programming, and the central observation is that subclassing, constructor-based parameterization, and cloning-then-modifying-the-clone are all aspects of the same thing despite C++'s efforts to treat them separately.
Required reading. Really.