Pointer array as a member behaves strange when passed to a function.

 

Pointer array doesn't work well when it is a member of a class or a struct. It returns bad pointers if it is passed to a function. Why???

class C { public: int c; };

struct S { C* array[2]; } s;

void F()
{
  s.array[0] = new C();
  s.array[1] = new C();
  G(s.array);
}

void G(C* &array[])
{
  Print(array[0].c);
  Print(array[1].c);  // bad pointer  WHY????
}
 
class C 
{
public: 
   int c; 
};

struct S 
{ 
   C* array[]; 
   S () {ArrayResize(array, 2);}
   ~S() 
   {
      for (int i = ArraySize(array) - 1; i >= 0; --i)
         if (POINTER_DYNAMIC == CheckPointer(array[i]))
            delete array[i];
   }
} s;

void F()
{
  s.array[0] = new C();
  s.array[1] = new C();
  G(s.array);
}

void G(C* &array[])
{
  Print(array[0].c);
  Print(array[1].c);
}
 
ALXIMIKS:

Thank you ALXIMIKS. Your code works.

But I still can't understand what is wrong with my code. Why doesn't fixed size array work?

 
minimax2000:

Thank you ALXIMIKS. Your code works.

But I still can't understand what is wrong with my code. Why doesn't fixed size array work?

I've just checked your code in 1010 build of client terminal. Your code works well.

So I need to know build number of client terminal you are using.

 
alexvd:

I've just checked your code in 1010 build of client terminal. Your code works well.

So I need to know build number of client terminal you are using.

Thank you alexvd. My question is solved.

My client's build number is 735. I will wait for my broker's update.