QUESTION
I saw THIS question on Java, which allows you to get a pointer to the Outer object from within a Nested object.
But how could you implement this in C++?
Not satisfactory solutions:
Storing a pointer to each object: (not memory efficient)
class Outer {
private:
int i;
class Inner {
int j;
Outer *outer;
};
Inner items[1000];
};
Wrapping the array in a class: (adds unnecessary (?) complexity)
class Outer {
private:
int i;
class Inner_array {
class Inner {
int j;
};
Inner items[1000];
// Build an interface around the array
typedef Inner (&array)[1000];
operator array();
// etc...
};
Inner items[1000];
Outer *outer;
};