I'm confused totally...

Ok, I create the class with the array:

ref class my_child
{
public:
  array<int>^ mas_1D;
 
  my_child() // constructor
  {
          mas_1D = gcnew array<int>(10);
  };
};

Next, I create one more class with the variables of the previous class:

ref class Father
{
public:
  my_child dear_baby;   // 1-st variable
 
  array<my_child^>^ dear_son; // 2-nd variable-array
  
  Father() // constructor
  {
          dear_son = gcnew array<my_child^>(5); 
  }; 
 
};

Next I define this class variables (in the programm body) and try to change it:

Father F;       
        F.dear_baby.mas_1D[1] = 12; // works properly
        F.dear_son[1]->mas_1D[1] = 23; //error!

There are no problem during compilation.
The "dear_baby" calls without any problem.
But the programm stops on the 3. string and shows error:
In the instance of the object reference not set to an object.
Something is wrong with "dear_son".

Thank you!

Something is wrong with "dear_son"

Yes, you do have room there for 5 children

dear_son = gcnew array<my_child^>(5);

but they need also be given birth first, so

F.dear_son[0] = gcnew my_child;
F.dear_son[0]->mas_1D[1] = 23;

So there were no objects yet, only handles to such, hence
>> not set to an instance of an object

Yeh, I have to give a birth like this:

for (int i=0; i<5; i++)
  F.dear_son[i] = gcnew my_child;

Thank you so much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.