![](http://franksecilia.tripod.com/AutoBot.gif)
Deep copy of a LL of virtual base classes
Anybody know how to perform a deep copy of a linked list of virtual base classes?
The problem here, is that the exact constructor to be called is unknown...
Is it possible?
Thank you for your bandwidth.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~Succinct Demos Online~
![](http://franksecilia.tripod.com/AutoBot.gif)
-- Succinct(Don't listen to me)
Use the virtual constructor idiom.
Your base class specify a virtual Create() method that returns an instance of the class. Each dervied class overrides it.
So insteading of calling new, you call the Create() method to allocate the object.
Similar to the prototype pattern in design patterns, I think.
..
Your base class specify a virtual Create() method that returns an instance of the class. Each dervied class overrides it.
So insteading of calling new, you call the Create() method to allocate the object.
Similar to the prototype pattern in design patterns, I think.
..
Ahhh, now that sounds like a plan, void!
thanks lots!
thanks lots!
-- Succinct(Don't listen to me)
I suppose it is just a matter of style, but it seems that CreateCopy or CreateNew would be a better choice in names. I would expect Create to do what would normally be done in the constructor and Destroy to do what would have been done in the destructor. There are sometimes benefits to seperating the physical and logical allocation/deallocation. One example is reducing memory fragmentation.
Keys to success: Ability, ambition and opportunity.
I agree, LilBudyWizer.
CreateCopy could take a parameter, the object being copied, too.
Neat stuff.
Thanks, guys.
-- Succinct
CreateCopy could take a parameter, the object being copied, too.
Neat stuff.
Thanks, guys.
-- Succinct
-- Succinct(Don't listen to me)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement