Assuming the constructor, destructor, and assignment operator is written properly, why can't I implement the copy-constructor like this:
MyClass::MyClass(const MyClass &other)
{
this->value = new Value(*(other.value));
}
Most of the examples I see, do this: (because they're dealing with arrays usually)
MyClass::MyClass(const MyClass &other)
{
Value *temp = new Value;
*temp = *(other.value);
this->value = temp;
}
But in the first example, if 'new' throws, 'other' isn't affected, and if Value's copy-constructor throws, won't 'new' free the allocated memory before propogating the exception?
As this is for a mini-smart pointer itself, I'm specifically avoiding the use of std::unique_ptr and other smart pointers.