← Back to Question List
C++ Quiz #35
Rule of Three Violation
This class manages dynamic memory. Which rule does it violate and what could go wrong?
📄 Code
1#include <iostream>2using namespace std;34class Matrix {5public:6 double* elements;7 int rows, cols;89 Matrix(int r, int c) : rows(r), cols(c) {10 elements = new double[rows * cols]();11 }1213 ~Matrix() {14 delete[] elements;15 }16 // No copy constructor or assignment operator defined17};1819void printFirst(Matrix m) { // pass by value20 cout << m.elements[0] << endl;21}