Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing child variables through higher level structures

Tags:

If I have these structures:

typedef struct { int x; } foo;
typedef struct { foo f; } bar;

Normally you would access x through b.f.x, but is there a way to set this up so that you can access element x without referring to f?

bar b;
b.x = ...

My first intuition is that you can't since there would be a possibility for name conflicts if two sub structures both had a member x and I can't figure out what the compile error would be. However, I recall working in some frameworks where this was possible.

In C++ I worked in a framework once where bar existed, and you could access its members as member variables this->x from a different class. I'm trying to figure out how that could be done.