Accessing child variables through higher level structures

后端 未结 8 1820
孤街浪徒
孤街浪徒 2020-12-09 17:41

If I have these structures:

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

Normally you would access x through

8条回答
  •  天涯浪人
    2020-12-09 18:09

    In C++, it is possible in two ways. The first is to use inheritence. The second is for bar to contain a reference member named x (int &x), and constructors that initialise x to refer to f.x.

    In C, it is not possible.

提交回复
热议问题