How to implement ICloneable without inviting future object-slicing
问题 My question is about how to implement the classic ICloneable interface in such a way that it won't lead to inadvertent object-slicing when a future programmer isn't paying close attention. Here's an example of the kind of programming error I'd like to detect (preferably at compile-time): #include <stdio.h> class ICloneable { public: virtual ICloneable * clone() const = 0; }; class A : public ICloneable { public: A() {} A(const A & rhs) {} virtual ICloneable * clone() const {return new A(*this