20 Nov
2017
20 Nov
'17
4:57 p.m.
Jonathan Coe wrote:
The pointer constructor is needed in migration paths from class heirarchies with a `Clone()` method. It also allows one to support objects coming from C_APIs.
Supporting X* create(...); X* copy( X const* ); void destroy( X* ); is appropriate for a cloning pointer, but hasn't really much to do with polymorphic values. struct Shape { virtual ~Shape() = default; Shape* clone() const = 0; void draw() = 0; }; Shape* createCircle( int r ); is admittedly less clear-cut. Looking at my old code, what I did was supply both a cloning pointer (U*) and a polymorphic value (U&&) types, the latter a simple wrapper over the former.