You want
std::vector
rather than a raw array, it can have its size set at runtime. (Uses new[]
under the hood to achieve that.) It would also be a nice idea to use something like std::mdspan
as your function parameter to be able to accept sub-matrices without copying them into new storage, but it's not supported in GCC yet.