I'm trying to get rid of some inefficiencies in my code. The current (simplified) version is this:

Then I would do this:Code:class matrix {double data*; matrix& operator=(const matrix& m) {}(for each element of m.data) { data[i] = m.data[i];}} matrix getminor(range_of_minor) {matrix m; copy_all_elements_of_this_in_range_to_m; return m;}

Am I copying matrices twice in the above code? Once when matrix::getminor creates a minor matrix and once when it assigns it to another one? Would it be better if I rewrote the function so that smaller_matrix is passed by reference to matrix::getminor and the values of data are copied directly?Code:matrix big_matrix, smaller_matrix; smaller_matrix = big_matrix.getminor(range_of_minor);