I have this piece of code that allocates and creates 5 objects of type MyClass:
#include <iostream>
#include <new>
struct MyClass {
int data;
};
int main () {
struct MyClass *p1=new MyClass[5];
p1->data=42;
return 0;
}
So,if i understand this correctly p1 is a pointer to a memory location of size Myclass[5] where these 5 objects are stored.So by using p1->data=42 is the int data updated for each of 5 objects.If so,how can i update data individually for a specific object?(Let's say the 3rd one)