Search code examples
c++-cli

2 dimensional List<T> in C++\CLI


I want to create a 2-dimensional List in C++\CLI. Question is how to declare it?

I have tried this:

List<List<int>^>^ H = gcnew List<List<int>>(); // Scoring matrix H
H->Add(gcnew List<int>() );

for (i = 0; i < n; i++) // Fill matrix H with 0
{
 for (j = 0; j < m; j++)
 {
 H[i]->Add(0);
 }
}

Then I get a lot of syntax errors, starting with this one:

error C3225: generic type argument for 'T' cannot be 'System::Collections::Generic::List', it must be a value type or a handle to a reference type


Solution

  • In this declaration

    List<List<int>^>^ H = gcnew List<List<int>>(); 
    

    The right type specifier does not correspond to the left type specifier. Should be

    List<List<int>^>^ H = gcnew List<List<int>^>();