In C++ we know that for a pointer of class we use (->
) arrow operator to access the members of that class like here:
#include
usi
you should read about difference between pointers and reference that might help you understand your problem.
In short, the difference is:
when you declare myclass *p
it's a pointer and you can access it's members with ->
, because p
points to memory location.
But as soon as you call p=new myclass[10];
p
starts to point to array and when you call p[n]
you get a reference, which members must be accessed using .
.
But if you use p->member = smth
that would be the same as if you called p[0].member = smth
, because number in []
is an offset from p
to where search for the next array member, for example (p + 5)->member = smth
would be same as p[5].member = smth