Thanks for your replies. The picture is clearer to me now.
Things that I learned:
I forgot to delete the
in line 77.
1. The address of a copy will never be equal to the address of the original. My overload of the == operator is not even needed as I would be doing a pointer to pointer comparison (not object to object) if I decided to use both :
1 2
|
member & operator=(member &&rhs)
member & operator=(member &rhs )
|
instead of the universal unifying assignment operator:
|
member & operator=(member rhs )
|
Although I am wondering now what address rhs has when the parameter is &&rhs.
2. std::swap is exception safe and could be used to build exception safe user defined overloads that swap built in types in the function body.
3. Using a swap makes sense in move semantics if the temporary's values are zeroed out (pointers set to null) to begin with such that the swap results in the object being moved from aquiring default (nullptr for pointers) values. The change is propagated to the original object (as if we passed a &rhs instead of a &&rhs).
Question : So a &&rhs behaves like an &rhs in the function/constructor body?
Question : When is the object moved from deleted? Are there no automatic measures to delete the moved from object except when it goes out of scope?
4. The assignment operator is "unifying" in the sense that it invokes the copy or move constructor to create the copy.
Question: Isn't the copy constructor not exception safe due to the call to new? So that if it is invoked by the assignment operator, the assignment operator wouldn't be exception safe as well?
Question: If the copy constructor is not exception safe (depends on answer to first question), would it be better to disable the copy constructor and just invoke move constructor all the time? How would this be done?
Question: Does the compiler check to see if the function cannot throw an exception when you use noexcept?
Thanks
Chris