I'm having some issues with structs.
If I have a couple of nested structs, is it possible to obtain the address of a member struct, or is this something that is not good practise. I.e. is it possible to obtain the address of fooStruct->barStruct->num ?. I am guessing that this is not possible, as the member would be something like an offset from the address of the encompassing struct (maybe??).
Also, if I do not allocate memory for barStruct member in both of the "fooStruct" and "blahStruct" then the "num" member seems to point at exactly the same location. I.e. updating one with a value changes the other. Why is this?Code:#include <iostream> using namespace std; typedef struct bar { int num; }BAR; typedef struct foo { BAR *barStruct; }FOO; int main(void) { FOO *fooStruct = new FOO; fooStruct->barStruct = new BAR; FOO *blahStruct = new FOO; blahStruct->barStruct = new BAR; fooStruct->barStruct->num = 10; blahStruct->barStruct->num = 11; cout << "fooStruct->barStruct->num: " << fooStruct->barStruct->num << endl; cout << "blahStruct->barStruct->num: " << blahStruct->barStruct->num << endl; return 0; }