Hello all,
I was reading a tutorial on C++ programming, and in one example a class, let's call it, MyExample is defined. In the main function the following statements were written:
Code:
MyExample *p=new MyExample[2];
.
.
.
p->SomeFunc(3,4);// .... (1)
p[1].SomeFunc(1,7);// ... (2)
where SomeFuc(int a, int b) is a public member function of the class that takes two int arguments.
To my understanding, the pointer p points to the first object of two objects of type MyExample that occupy consecutive memory locations. On the other hand, P[0] and p[1] are the first and second objects, respectively. I guess that's why we used -> with p in (1) because it's a pointer, while we used . with p[1] in (2) because it's an object, right?
It also seems to me that the statement (1) passes the int arguments 3 and 4 to both objects p[0] and [p1]. Is this how it works?
Thanks