Generic multidimensional array in C++ #include &lt;iostream&gt;
#include &lt;memory&gt;
using std::cout;
using std::endl;

template&lt;typename T, int dimension = 1&gt;
class Array
{
private:
    std::unique_ptr&lt;T[]&gt; pointer;
    int size[dimension];
    int realSize;

public:
    Array()
    {
    }

    template&lt;typename... Ns&gt;
    Array(Ns... ns)
    : realSize(1)
    {
        create(1, ns...);
    }

private:
    template&lt;typename... Ns&gt;
    void create(int d, int n, Ns... ns)
    {
        realSize *= n;
        size[d - 1] = n;
        create(d + 1, ns...);
    }

    void create(int d)
    {
        pointer = std::unique_ptr&lt;T[]&gt;(new T[realSize]);
    }

    int computeSubSize(int d) const
    {
        if (d == dimension)
        {
            return 1;
        }
        return size[d] * computeSubSize(d + 1);
    }

    template&lt;typename... Ns&gt;
    int getIndex(int d, int n, Ns... ns) const
    {
        return n * computeSubSize(d) + getIndex(d + 1, ns...);
    }

    int getIndex(int d) const
    {
        return 0;
    }

public:
    template&lt;typename... Ns&gt;
    T&amp; operator()(Ns... ns) const
    {
        return pointer[getIndex(1, ns...)];
    }

    int getSize(int d = 1) const
    {
        return size[d - 1];
    }
};

int main()
{
    constexpr int N = 10;
    Array&lt;int&gt; a(N);
    for (int i = 0; i &lt; a.getSize(); ++i)
    {
        a(i) = i + 1;
        cout &lt;&lt; a(i) &lt;&lt; ' ';
    }
    cout &lt;&lt; '\n' &lt;&lt; endl;
    Array&lt;int, 2&gt; a2(N, N * 2);
    for (int i = 0; i &lt; a2.getSize(1); ++i)
    {
        for (int j = 0; j &lt; a2.getSize(2); ++j)
        {
            a2(i, j) = i + j + 2;
            if (a2(i, j) &lt; 10)
            {
                cout &lt;&lt; '0';
            }
            cout &lt;&lt; a2(i, j) &lt;&lt; ' ';
        }
        cout &lt;&lt; endl;
    }
    return 0;
}


Output


1 2 3 4 5 6 7 8 9 10 

02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 
03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 
04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 
05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 
06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 
07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 
08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 
09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
No need for an empty constructor in C++11:


Array()
{
}



You can just use a default constructor:

Array() = default;

It's a little confusing to have multiple public/private sections.  Here, you can just put all the public code under the same keyword.
You could make your structure more useful by providing iterators.  This will, for instance, allow you to use range based for-loops instead of plain ones for iterating through this structure.
You don't need std::endl if you just need newlines.  Just output "\n" instead for this.  More info about this can be found here.
It's unnecessary to have your own return 0 at the end of main() in C++.  The compiler will provide this return for you.