Dynamic array of struct into a struct

struct subContainer {
int sCint;
string sCstr;
};

struct mainContainer {
....
....
struct subContainer *p2sC;
....
} mCinstance;


mCinstance.p2sC = new subContainer[N];

sizsC = sizeof(subContainer);


How do I access to the elements sCint, sCstr in the array of N subContainer pointed by p2sC?

I tried different syntaxes and just got seg-fault. I cannot figure it out...
Last edited on
mCinstance.p2sC[i].sCint is the sCint of the ith element.
If you get segfaults, it probably means that you didn't initialize some pointer. Post the code you tried.
Code with syntax errors will not compile (unless the syntax is valid just not what you wanted.)
Topic archived. No new replies allowed.