For a project we have to make a class and use a dynamic array to create several matrices. We cannot use a Vector. We have to write our copy constructor, destructor, assignment operator, move constructor, move assignment operator.
I have several questions.
1)Can someone help me come up with the move functions. I am confused on how they work
2) would this be ok for my copy and assignment functions?
Answering there instead of your newer post as this one actually has code and more full info.
1) Your copy constructor is a mess. Swap idiom generally is not applied to copy constructors. Additionally you do not need to check for self...copying? Look into delegating constructors too, as you seem to might use them here.
2) When you do swap-based assigment operator you do not need self-assigment check and you should fully delegate all work to copy constructor. Canonical copy/move-assigment operator:
1 2 3 4 5 6
const A& A::operator=(A other)
{
using std::swap; //Allowing user-defined swaps to be ADL-found
swap(*this, other);
return *this;
}
Note taking argument by value. It allow it to work in both copy and move contexts.
You will either need to implement move constructor and use std::swap (will not work with old C++ versions) or roll your own swap for your class and do memberwise swapping.