Vpp Man
Vpp Man

Reputation: 2546

Multidimensional array C++.net CLI

array<int,2>^ a = gcnew array<int,2>(5,5);
    for(int i=0; i<5; i++)
    {
        for(int j=0; j<5; j++)
        {
            a[i][j] = 0;
        }
    }

The above code is giving me the following two errors:

Error 1 error C3262: invalid array indexing: 1 dimension(s) specified for 2-dimensional 'cli::array ^'

Error 2 error C2109: subscript requires array or pointer type

Why is it so? :(

Upvotes: 1

Views: 1544

Answers (2)

Vlad from Moscow
Vlad from Moscow

Reputation: 311038

Use trhe following form of indexing

a[i, j] = 0;

Upvotes: 2

Vpp Man
Vpp Man

Reputation: 2546

Found the solution!

Instead of using:

a[i][j] = 0;

It should be like this:

a[i,j] = 0;

Upvotes: 3

Related Questions