MFC Programmer's SourceBook : Thinking in C++
Bruce Eckel's Thinking in C++, 2nd Ed Contents | Prev | Next

C: Simulating virtual constructors

TODO: Incorporate this with the design patterns chapter, as a creational pattern

During a constructor call, the virtual mechanism does not operate (early binding occurs). Sometimes this is awkward.

In addition, you may want to organize your code so you don’t have to select an exact type of constructor when creating an object. That is, you’d like to say, “I don’t know precisely what type of object you are, but here’s the information: Create yourself.” This appendix demonstrates two approaches to “virtual construction.” The first is a full-blown technique that works on both the stack and the heap, but is also fairly complex to implement. The second is much simpler to implement and maintain, but restricts you to creating objects on the heap.

Contents | Prev | Next


Go to CodeGuru.com
Contact: webmaster@codeguru.com
© Copyright 1997-1999 CodeGuru