In fact, you use p[index].x and p[index].y to access struct elements inside an array, because in this case you use a pointer to refer to a dynamically allocated array.
The ptr->member operator is simply a shorthand for (*ptr).member . To use it, you need to specify the pointer on the left side:
Point *p = new Point; p->x = 12.34; p->y = 56.78;
Note that even for a dynamically allocated array, a -> operator would work:
Point *p = new Point[10]; p->x = 12.34; p->y = 56.78;
It is equivalent
p[0].x = 12.34; p[0].y = 56.78;
because the pointer to the array is equal to the pointer to its first element.
source share