How to create array of objects in Visual Studio C++

  • Thread starter Thread starter RatsonK
  • Start date Start date
R

RatsonK

Guest
I have a class contains settings parameters. I want to create an array of this parameters.

This is the class:

ref class Global_Params_Struct
{
public:

...parameters

public:

... methods

}

In class 'Form1':

public ref class Form1 : public System::Windows::Forms::Form
{

public:
Form1(void)
{
for(Byte i = 0; i < 10; i++)
this->Global_Params_Array = gcnew Global_Params_Struct;
}

private: array<Global_Params_Struct^>^ Global_Params_Array;

}

This code is compiled correctly, but an exception arises due to the internal line of the 'for' loop:

System.NullReferenceException: 'Object reference not set to an instance of an object.'

How should I create an array of 'Global_Params_Struct' class?

Continue reading...
 
Back
Top