typedef T* pointer;
An exception-safe assignment operator is more than I can take on at the moment. I can give you examples and you'll have to figure out how to make yours exception safe.
Exception safe assignment operators are typically implemented with the copy-swap idiom. Here is a trivial example:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
class Foo {
int x;
int y;
public:
Foo& operator=( Foo rhs ) // Take a _copy_ of the rvalue
{
// Swap all the elements
std::swap( x, rhs.x );
std::swap( y, rhs.y );
return *this;
}
};
|
This works provided that std::swap() does not throw. [Note that the std::swap template won't throw for POD-types, but there is no guarantee for user-defined types. You have to write swap() for your
user-defined types if you want to make the guarantee].
Exception safety simply means that the assignment operator leaves the "assigned-to" object in a valid, known state if an exception occurs. In the case above, provided that swap does not throw, the only other thing that can throw is Foo's copy constructor. If it does, then the "assigned-to" object is left unchanged.
In your assignment operator, you do "uncreate() followed by create()". Your uncreate() method deallocates memory and runs destructors; your create method allocates memory and calls constructors. Any of those operations may throw, meaning that if an exception occurs, your "assigned-to" object will be left in some unknown, possibly even invalid state.