as we all know declaration of array is pretty simple
type name[size];
but when I compile my C++ as CLI/Winform It doesn't work, I've found the following on MSDN which explains this new syntex, but for some reasone I still get strange errors.
When I declared the array the following way, it's compiled with no problems,but when ever the array is manipulated the program crash. (I tested it on a simple program with a button, still the same)
array<int>^ aiArray; //declaration - no problem
aiArray[0] = 5; //after executing it the program crash
Here is the error i get after the crash:
An unhandled exception of type 'System.NullReferenceException' occurred in test.exe
Additional information: Object reference not set to an instance of an object.
You need to create the array, not just declare a local variable. Try this:
array<int>^ aiArray;
aiArray = gcnew array<int>(10);
aiArray[0] = 5;
If you're familiar with C#, this should look familiar. If you're familiar with C++ and not C#, here's what's going on: What you have is roughly equivalent to int* aiArray;
in unmanaged C++. You would need to do aiArray = new int[10];
before you can use the unmanaged array.