The code is supposed to take two matrices from txt files, multiply them and display the result, it works but most of the time it crashes after displaying the result. Can anyone tell me whats wrong, is it the dynamic memory?
You did not provide a copy constructor, so compiler generated one for you. It copies elements one-by-one, including pointers. So in line matrix C = A*B; C will contain same pointers as unnamed temporary returned by multiplication. After that line temporary is destroyed, freeing memory. After that access to C elememts creates UB. It might not crash right away, but destructor will try to delete memoty again, leading to double delete and high probability of crash.