# RAII and dynamic memory in classes (part 2)

This lesson contains approximately 18 minutes of video content.

### Our VectorInt implementation continued

#### Activity: Matrix resize

Activity Prompt:

In this activity, you will finish a partially complete implementation of a `MatrixInt` class. The `MatrixInt` should allocate and deallocate a non-empty `rows_` x `cols_` array of `int`s in its constructor and destructor, respectively. You will also have to implement the `Resize` method, which will resize the non-empty 2D array to the dimensions specified. If the dimensions become smaller, values at the right and/or bottom edges will not be retained. If the dimensions become bigger, new values at the right and/or bottom will be initialized to zero.

`Resize` example:
```{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} ```

After `Resize(2,4)` is called:
```{{1, 2, 3, 0}, {4, 5, 6, 0}} ```
Function Description
`MatrixInt(unsigned int rows, unsigned int cols)` Constructor. Should dynamically allocate the non-empty 2D array of ints `matrix_` with `rows` rows and `cols` cols, initialized to be all zeros.

If `rows` or `cols` are invalid, throw a `std::invalid_argument` exception.
`~MatrixInt()` Destructor. Should deallocate `matrix_` completely.
`void Resize(unsigned int new_rows, unsigned int new_cols)` Resizes the matrix according to the specifications above.

If `new_rows` or `new_cols` is invalid, throw a `std::invalid_argument` exception.
`int Get(unsigned int row, unsigned int col)` Provided: returns the value of the matrix at `(row, col)`.
`void Set(unsigned int row, unsigned int col, int new_val)` Provided: sets the value of the matrix at `(row, col)` to `new_val`.
`friend std::ostream& operator<<(std::ostream& os, const MatrixInt& matrix)` Provided: prints the matrix to `os`.
Data Member Description
`int** matrix_` Pointer to the non-empty 2D matrix.
`unsigned int rows_` Amount of rows (height).
`unsigned int cols_` Amount of cols (width)