Matrix OOP implementation using C++11 and C++14 I know that other people already did the same already,
but I'm learning C++ (C++11/14) coming from C (I'm reading Programming: Principles and Practice Using C++, by Bjarne Stroustrup), and this is my OOP implementation of a matrix (N by M size).

At the moment it doesn't use template for generic types and uses double, and all it does is represent a matrix, but doesn't implement any calculation function members yet.
I'm using the C++ PIMPL idiom (using C++11's unique_ptr and C++14's make_unique), and the subscript [] operator overload.

I'd like to know if I'm using a good programming pattern (or a bad antipattern) and in the correct C++ way of doing things (ex. program structure, files and organization, types etc...). Please if you can keep it simple, as I'm still missing parts of the language I haven't learned yet.

File main.cpp:

#include &lt;iostream&gt;
#include &lt;memory&gt;

#include "Matrix.hpp"

using namespace std;
using namespace zgt;

constexpr size_t num_elements{ 3};

/*
 Outputs:
 1, 2, 3
 4, 5, 6
 7, 8, 9
 */
int main() {
    Matrix m{ num_elements }; // Squared matrix

    double inc{ 1 };
    for (size_t i{ 0 }; i &lt; num_elements; i++) {
        for (size_t j{ 0 }; j &lt; num_elements; j++) {
            m[i][j] = inc++;
        }
    }

    for (size_t i{ 0 }; i &lt; num_elements; i++) {
        for (size_t j{ 0 }; j &lt; num_elements; j++) {
            if (j == 0) {
                cout &lt;&lt; m[i][j];
            } else {
                cout &lt;&lt; ", " &lt;&lt; m[i][j];
            }
        }

        cout &lt;&lt; endl;
    }

    return 0;
}


File Matrix.cpp:

#include "Matrix.hpp"

using namespace std;
using namespace zgt;

struct Matrix::_impl {
    unique_ptr&lt;unique_ptr&lt;MatrixRow&gt;[]&gt; _m;

    _impl(size_t rows, size_t cols): _m(make_unique&lt;unique_ptr&lt;MatrixRow&gt;[]&gt;(rows)) {
        for (size_t i{ 0 }; i &lt; cols; i++) {
            _m[i] = make_unique&lt;MatrixRow&gt;(cols);
        }
    }
};

MatrixRow&amp; Matrix::operator[](size_t index) {
    return *(pimpl-&gt;_m[index]);
}

Matrix::Matrix(size_t rows, size_t cols) : pimpl(make_unique&lt;_impl&gt;(rows, cols)) {}
Matrix::Matrix(size_t size) : Matrix::Matrix(size, size) {}
Matrix::~Matrix() = default;


File Matrix.hpp:

#ifndef Matrix_hpp
#define Matrix_hpp

#include &lt;iostream&gt;
#include &lt;memory&gt;

#include "MatrixRow.hpp"

namespace zgt {
    class Matrix{
        struct _impl;
        std::unique_ptr&lt;_impl&gt; pimpl;
    public:
        Matrix(size_t rows, size_t cols);
        Matrix(size_t size); // [size][size]
        ~Matrix();

        MatrixRow&amp; operator[](size_t index);
    };
}

#endif


File MatrixRow.cpp

#include "MatrixRow.hpp"

using namespace std;
using namespace zgt;

struct MatrixRow::_impl {
    unique_ptr&lt;double[]&gt; _v;

    _impl(size_t cols): _v(make_unique&lt;double[]&gt;(cols)) {}
};

double&amp; MatrixRow::operator[](size_t index) {
    return pimpl-&gt;_v[index];
}

MatrixRow::MatrixRow(size_t cols) : pimpl(make_unique&lt;_impl&gt;(cols)) {}
MatrixRow::~MatrixRow() = default;


File MatrixRow.hpp:

#ifndef MatrixRow_hpp
#define MatrixRow_hpp

#include &lt;iostream&gt;
#include &lt;memory&gt;

namespace zgt {
    class MatrixRow{
        struct _impl;
        std::unique_ptr&lt;_impl&gt; pimpl;
    public:
        MatrixRow(size_t cols);
        ~MatrixRow();

        double&amp; operator[](size_t index);
    };
}

#endif
Lets start from the usage:


It is not possible to write range loops with the current version
no rowcount() and columncount() (or anything similar). So it is not possible to actually traverse matrix
operator[]() won't work on const objects, since there is no operator[](std::size_t index) const.


Clarity and cleanliness:


nuke pimpl. I'm serious, it doesn't add much benefit here. In fact, the compilation might be increased by pimpl, since matrix is very lightweight anyway.
#include &lt;iostream&gt; header is not needed, should be removed.
double indirection. _impl should actually be MatrixRow. But if pimpl is gonna get nuked, it will be embedded into matrix itself.
std::vector&lt;&gt; would be much better fit here.

Nitpicks:
destructor is generated for you automatically. defaulting it is redundant.


Some general guidelines:


OOP is usually mixed with some functional programming in C++. For example, templates.
C++ code usually tries to provide some default behavior that is correct and safe, and some access to underlying implementation that when accessed lets programmer to take all of the control to himself (literally everything).


Recommendation for next iteration:

I think that std::vector&lt;T&gt; will be the best fit here. Calculating the index to jump at should be pretty easy (it is what compiler does for us anyway). I think it will be okay to return T* from operator[](), because users know they shouldn't mess with it, but making some small struct would good as well. Something like std::array_view&lt;T&gt; would be nice (though it seems like it is not in the standard yet, even in C++17). Also, you get iterators for free with vector approach. 

Just write:

auto begin()
{
    return storage.begin();
}

auto end()
{
    return storage.end();
}


As a result, you get range loop for free as well.