Implement and use virtual Partition copy constructor clone() (#759726)
Final step for full polymorphic handling of Partition objects is to implement a virtual copy constructor. C++ doesn't directly support virtual copy constructors, so instead use the virtual copy constructor idiom [1]. (Just a virtual method called clone() which is implemented in every polymorphic class and creates a clone of the current object and returns a pointer to it). Then replace all calls to the (monomorphic) Partition object copy constructor throughout the code, except in the clone() implementation itself, with calls to the new virtual clone() method "virtual copy constructor". Also have to make the Partition destructor virtual too [2][3] so that the derived class destructor is called when deleting using a base class pointer. C++ supports this directly. [1] Wikibooks: More C++ Idioms / Virtual Constructor https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Virtual_Constructor [2] When to use virtual destructors? http://stackoverflow.com/questions/461203/when-to-use-virtual-destructors [3] Virtuality Guideline #4: A base class destructor should be either public and virtual, or protected and nonvirtual http://www.gotw.ca/publications/mill18.htm Bug 759726 - Implement Partition object polymorphism SQUASH: When first using pointers to Partition and calling delete
parent
656e1709
Please register or sign in to comment