Whenever you write one of the copy constructors, copy assignment operator, or destructor, you must do all three. This is the Big Three, and the previous rule is the Rule of Three.
Right now, your copy constructor is not making a deep copy. I also recommend that you use the copy and swap idiom whenever you implement The Big Three. * In its current form, your operator= incorrect.
This may be a training exercise, but you should always give the lessons responsibly. Right now you have two: memory resource management and Matrix . You must separate them so that you have one class that processes the resource and another that uses the specified class to use the resource.
This utility class will need to implement The Big Three, but the user class really will not need to implement any of them, because implicitly generated ones will be processed properly thanks to the utility class.
Of course, such a class already exists as std::vector .
source share