Jun 21, 2011 at 9:42pm UTC
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 Jun 21, 2011 at 9:43pm UTC
Jun 21, 2011 at 9:47pm UTC
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.
Jun 21, 2011 at 9:51pm UTC
Code with syntax errors will not compile (unless the syntax is valid just not what you wanted.)