I think you are mixing up copy ctors with the clone function.
The clone function does not actually copy anything. It just invokes the desired copy ctor. In order to actually copy an object, you need a functioning copy ctor.
In my understanding, the clone() method creates a new object of the type passed in. |
This is correct.
But when one says you are doing a deep copy it means that you have allocated new memory on the heap and have copied each and every element of the object being copied from. |
Whether or not this is true depends on how the copy constructor is formed. A proper copy ctor will copy all of it's members appropriately.
All clone does is make it so you don't need to know what kind of vehicle you're copying. if 'a' is a Car, then 'a->clone();' makes an identical Car. if 'a' is a Truck, then 'a->clone()' makes an identical Truck.
How it makes an identical Truck/Car depends on Truck's/Car's copy constructor. If they don't properly copy themselves then of course it won't work. Cloning depends on the copy ctor.
in the copy ctor of the Person how does that resort to deep copy when say vehicle a has done some car modification() and you need that to be reflected in vehicle b. |
If Car's copy ctor properly copies itself, all modifications should be reflected in the copy.
In the arr class, i did a clone() that would have created a new object just like it would have created a new object for the abstract method()...so why the difference? |
Your arr class did not properly copy itself. It failed to do a deep copy of its 'p' member.